Ejemplo n.º 1
0
		bool Connection::check () {
		
			if (mysql_ping(get())==0) return true;
			
			auto guard=AtExit([&] () {	destroy();	});
			
			auto code=mysql_errno(get());
			if (
				(code==CR_SERVER_GONE_ERROR) ||
				//	The documentation for mysql_ping
				//	explicitly says that it doesn't cause
				//	CR_SERVER_LOST:
				//
				//	http://dev.mysql.com/doc/refman/5.7/en/mysql-ping.html
				//
				//	However, if you manually close all
				//	this data provider's connections on
				//	the server, and then watch as this
				//	function executes in the debugger,
				//	you'll discover that mysql_ping
				//	absolutely does cause CR_SERVER_LOST.
				(code==CR_SERVER_LOST)
			) return false;
			
			Raise();
		
		}
Ejemplo n.º 2
0
			AtomicType Atomic (Args &&... args) {
			
				lock.Acquire();
				auto guard=AtExit([&] () {	lock.Release();	});
				
				AtomicType retr;
				atomic(retr,std::forward<Args>(args)...);
				
				return retr;
			
			}
Ejemplo n.º 3
0
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID ptr)
{
	if(reason == DLL_PROCESS_ATTACH)
	{
		FP_HModule = (HMODULE)hinst;
		AtExit(idAtExit);
	}

	BOOL res = FP_PluginStartup(reason);

	if(reason == DLL_PROCESS_DETACH)
	{
		CallAtExit();
	}

	return res;
}
Ejemplo n.º 4
0
ExtFunc void InitRobot(char *robotProg)
{
	int to[2], from[2];
	int status;
	MyEvent event;

	signal(SIGPIPE, CatchPipe);
	AtExit(CloseRobot);
	if (pipe(to) || pipe(from))
		die("pipe");
	robotProcess = fork();
	if (robotProcess < 0)
		die("fork");
	if (robotProcess == 0) {
		dup2(to[0], STDIN_FILENO);
		dup2(from[1], STDOUT_FILENO);
		close(to[0]);
		close(to[1]);
		close(from[0]);
		close(from[1]);
		execl("/bin/sh", "sh", "-c", robotProg, NULL);
		die("execl failed");
	}
	close(to[0]);
	close(from[1]);
	toRobotFd = to[1];
	robotGen.fd = fromRobotFd = from[0];
	if (!(toRobot = fdopen(toRobotFd, "w")))
		die("fdopen");
	if ((status = fcntl(fromRobotFd, F_GETFL, 0)) < 0)
		die("fcntl/F_GETFL");
	status |= O_NONBLOCK;
	if (fcntl(fromRobotFd, F_SETFL, status) < 0)
		die("fcntl/F_SETFL");
	AddEventGen(&robotGen);
	RobotCmd(1, "Version %d\n", ROBOT_VERSION);
	if (WaitMyEvent(&event, EM_robot) != E_robot)
		fatal("Robot didn't start successfully");
	if (1 > sscanf(event.u.robot.data, "Version %d", &robotVersion)
			|| robotVersion < 1)
		fatal("Invalid Version line from robot");
	if (robotVersion > ROBOT_VERSION)
		robotVersion = ROBOT_VERSION;
}
Ejemplo n.º 5
0
Archivo: inet.c Proyecto: bbusse/netris
ExtFunc void InitNet(void)
{
	lostConn = 0;
	gotEndConn = 0;
	AtExit(CloseNet);
}