コード例 #1
0
ファイル: main.c プロジェクト: vasubabu/WebServer
/*******************************************************************************
@purpose: START POINT
*******************************************************************************/
int main(int argc, char *argv[])
{
    switch(getStartupParams(argc, argv))
    {
    case SHOW_INTERFACES:
            printInterfaces();
            break;
    case SERVER_START:
            InitServer();
            break;
   /*case SERVER_STOP:      //TODO
            break;
    case SERVER_RESTART:
            break;*/
    case CHECK_CONFIG:
            checkConfiguration();
            break;
        case SHOW_HELP:
        case SHOW_HELP_LONG:
    default:
            printf("\tUsage:\n"
                   "\t--i    get available interfaces\n"
                   "\t--t    check configuration\n"
                   "\t--k    to start webserver\n"
                   "\t--h    print this text\n");
            return 0;
    }
}
コード例 #2
0
ファイル: proxy2.c プロジェクト: zhiliang729/ctest
int main(int argc, char *argv[])
{
    	int nListenSock = -1, nLocalSock = -1, nRemoteSock = -1;
	pid_t nChild;	    	
	if (argc != 2) 							/* 命令行参数:“proxy1 本地端口” */
	{
    		PrintLog(stdout, "proxy1 LOCALPORT\n");
    		return 1;
    	}
    	/* ---------------------------父进程------------------------------- */
    											/* ① 创建侦听套接字 */
    	ASSERT(CreateSock(&nListenSock, atoi(argv[1]), 8) == 0);	
    	PrintLog(stdout, "listen service: service is activated.");
    	InitServer();							/* ② 进程转后台运行 */
  	while (1)
   	{
     										/* ③ 等待并创建连接套接字 */
    		if (!VERIFY(AcceptSock(&nLocalSock, nListenSock) == 0)) 	
				continue;					/* ③ 继续等待 */
		VERIFY((nChild = fork()) >= 0);		/* ④ 创建子进程 */
		if (nChild == 0) break;				/* 子进程跳转到子进程代码 */
		close(nLocalSock);					/* ⑤ 父进程关闭连接套接字 */
	}
	/* ---------------------------子进程------------------------------- */
	close(nListenSock);						/* ⑦ 子进程关闭侦听套接字 */
								/* 解析HTTP报文头,并与目标服务器建立连接 */
	if (HttpConnect(nLocalSock, &nRemoteSock) == 0)
		SendReciveServer(nLocalSock, nRemoteSock);			/* 通信转发 */
    	if (nLocalSock >= 0) close(nLocalSock);  /* ⑨ 子进程关闭本地端套接字 */
    	if (nRemoteSock >= 0) close(nRemoteSock);/* ⑨ 子进程关闭目标端套接字 */
}
コード例 #3
0
ファイル: UpdateThread.cpp プロジェクト: vizcount/work
///////////////////////////////////////////////////////////////////////////////
//
// 函数功能描述:Save线程消息分发
// 输入:
// 输出:
// 返回值:
// 其它说明:
//
///////////////////////////////////////////////////////////////////////////////
DWORD CUpdateThread::DispatchMessage(T_Message *Msg)
{
    DWORD dwRet = 0;
	if (!bIsinit)
	{
		InitServer();
		bIsinit = TRUE;
	}

    switch (Msg->dwMsgParam)
    {
	case E_FTP_GET_FILE_FROM_SERVER:  //下载网站dat文件及其他单个文件
        {
			if (bFtpDownload)
			{
				StartDownload(E_FTP_GET_FILE_FROM_SERVER,Msg->dwData);
			}
			else
			{
				StartDownload(E_HTTP_GET_FILE_FROM_SERVER,Msg->dwData);
			}
			
        }
		break;
	case MSG_TIMER:
		{
			
		}
		break;
    default:
        break;
    }
    return 0;
}
コード例 #4
0
ファイル: network.c プロジェクト: Mudenng/pudge
/*
 * Start Master init event, and wait client
 */
int StartMaster(void *arg) {
    char *ip = ((SERVER_START_ARG *)arg)->ip;
    int port = ((SERVER_START_ARG *)arg)->port;
    int max_conn = ((SERVER_START_ARG *)arg)->max_conn;
    event_callback_fn recv_callback_fn = ((SERVER_START_ARG *)arg)->recv_callback_fn;
    // prepare socket
    int server_sockfd = PrepareSocket();
    if ( InitServer(server_sockfd, ip, port, max_conn) != 0 ) {
        printf("Master start error.\n");
        return -1;
    }

    // make non_blocking
    evutil_make_listen_socket_reuseable(server_sockfd);

    // init event
    struct event_base *base = event_base_new();
    assert(base != NULL);
    struct event *listen_event;
    callback_arg callarg;
    callarg.base = base;
    callarg.callback_fn = recv_callback_fn;
    listen_event = event_new(base, server_sockfd, EV_READ|EV_PERSIST, MasterAcceptHandle, (void *)&callarg);
    event_add(listen_event, NULL);

    // start event
    printf("Master Start\n");
    event_base_dispatch(base);

    return server_sockfd;
}
コード例 #5
0
ファイル: test.c プロジェクト: zhoujianhanyu/SWffmpeg
int main()
{	
	signal(SIGHUP, handle_signal);
	signal(SIGINT, handle_signal);
	signal(SIGQUIT, handle_signal);

	pPacketQueue = (SWPacketQueue *)InitPacketQueue();
	
	if (!pPacketQueue)
	{
		exit(1);
	}
	
	pMServer = InitServer(pPacketQueue, PORT);
	
	pWrite = InitAviWrite(pPacketQueue, "test.asf");
	
	
	StartServer(pMServer);
    StartThread(pWrite);
    
    
	while(flag);
    main_exit();	
	return 0;
}
コード例 #6
0
ファイル: thread_main.c プロジェクト: chenneal/postsi
void InitStorage(void)
{
	InitServerBuffer();
	InitRecord();
	InitTransactionList();
	InitServer();
}
コード例 #7
0
int main (int argc, char *argv[])
{
    char buf[4];
    if(argc == 2){ 
	InitServer(atoi(argv[1]));
    } else { 
	printf("not enough argument.\nusage: sudo ./a.out <port number>\n\n");
	exit(1);
    }
    if (wiringPiSetup () == -1) exit (1) ;
        pinMode (0, OUTPUT);
	digitalWrite (0, LOW) ;

    int pin = 0; //GPIO 17
    if (softPwmCreate(0,0,200) != 0){
	fprintf (stdout, "oops: %s\n", strerror (errno)) ;
	return 1 ;
    }
    
    while(1){
	while((n = read(sock,buf,4)) > 0){
	    Servo(pin, buf);
        }
    }

    return 1;
}
コード例 #8
0
ファイル: DarkPeer.cpp プロジェクト: adrikim/thiefmp
CDarkPeer::CDarkPeer(NetState state) : m_csEnumResponse("peer enum response")
{
	m_pDP = NULL;
	m_pDeviceAddress = NULL;
	m_pHostAddress = NULL;
	m_gsc = NULL;
	m_pSessionMgr = NULL;
	m_queuePeak = 0;
	m_dpnidHost = kInvalidHostID;

	m_DarkQueue.Clear();
	NewReceiveQueue.Clear();

	if (state == STATE_Client)
	{
		m_bReceivedExistingPlayers = false;

		InitClient();
		m_ConnectedEvent = CreateEvent(NULL, true, false, NULL);
	}
	else if (state == STATE_Host)
	{
		InitServer();

		// Start up global connection, if set to advertise server
		if (Cfg.GetBool("ListOnGlobal"))
		{
			if (!InitGlobalLink())
				Log.Print("Failed to list server to global.");
		}
	}

	EventManager::Broadcast(ET_NetStart, NULL);
	EventManager::RegisterListener(ET_GameMode, this);
	EventManager::RegisterListener(ET_MissionLoaded, this);

#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	if (!m_bLoadedBinds)
	{
		g_pInputBinder->LoadBndFile("user_mp.bnd", 0x21, NULL);
		m_bLoadedBinds = true;
	}
	if (!m_bLoadedNetCommands)
	{
		InitNetCommands();
		m_bLoadedNetCommands = true;
	}

	NetDisconnectListenerInit();

#if (GAME == GAME_THIEF)
	MemPatcher::WritePtr(g_MultiplayerPatches);
	MemPatcher::WriteRaw(g_MultiplayerRawPatches, NULL, NULL);

	PatchCommands(true);
#endif
	Debug.SetExceptionFilter(); // enable crash logger
#endif
}
コード例 #9
0
int SetServerListenState(ARG_UNUSED EvalContext *ctx, ARG_UNUSED size_t queue_size)
{
    if (!SERVER_LISTEN)
    {
        Log(LOG_LEVEL_VERBOSE, "Disable listening on port is only supported in CFEngine Enterprise");
    }

    return InitServer(queue_size);
}
コード例 #10
0
int SetServerListenState(size_t queue_size)
{
    if (!SERVER_LISTEN)
    {
        CfOut(cf_verbose, "", " !! Disable listening on port is only supported in CFEngine Enterprise");
    }

    return InitServer(queue_size);
}
コード例 #11
0
ファイル: program.c プロジェクト: alb001/IRIServer
int main(int argc,char**argv)
{
	// TODO: pass on commad-line arguments.
	InitServer(argc,argv);
	// TODO: check if successful.
	StartServer();
	printf("Done.\n");
	return EXIT_SUCCESS;
}
コード例 #12
0
ファイル: server.cpp プロジェクト: petrpavlik/rnl
	CServer::CServer(RNL::eProtocol protocol, unsigned int port, CController *controller)
	{
		m_thread.m_server = this;
		if(!InitServer(protocol, port, controller)) return;
		//ioctl(sd, FIOSNBIO, &arg);
		int nonblocking = 1;
		ioctlsocket(m_socket, FIONBIO, (unsigned long*) &nonblocking);
		m_bRun = true;
		m_thread.Launch();
	}
コード例 #13
0
ファイル: CmdLine.cpp プロジェクト: Seldom/miranda-ng
extern "C" int __declspec(dllexport) Load(void)
{
	mir_getLP(&pluginInfo);
 	mir_getCLI();

	if (InitServer())
		MessageBox(0, TranslateT("Could not initialize CmdLine plugin property"), TranslateT("Error"), MB_ICONEXCLAMATION | MB_OK);

	HookEvents();
	return 0;
}
コード例 #14
0
ファイル: gate_server.cpp プロジェクト: albertclass/XStudio
int ServerMain( int argc, char **argv )
{
	XGC_ASSERT_RETURN( argc > 1, -1 );

	if( InitServer( argv[1], InitGateServer ) )
	{
		LoopServer( OnceGateServer );
	}

	FiniServer( FiniGateServer, nullptr );
	return 0;
}
コード例 #15
0
ファイル: Test_operation.c プロジェクト: wcapellan/zte-code
void Test_Operation()// ²âÊÔ²Ù×÷
{
	int choice = 1;
	Display_Menu();
	while(choice!=0)
	{
		Display_SubMenu();
		scanf("%d",&choice);
		printf("*****************THE RESULT OF TESTING:***********\n");
		printf("\n");
		switch(choice)
		{
		case  88:ShowCommand();
			break;
		case 100:InitServer();
			break;
		case 101:ShowServerInfo();
			break;
		case 111:Display_Plnode_Client_111();
			break;
		case 201:Test_201();
			break;
		case 202:Test_202();
			break;
		case 301:Test_301();
			break;
		case 3020:Init_Test302();
			break;
		case 302:Test_302();
			break;
		case 401:Test_401();
			break;
		case 402:Test_402();
			break;
		case 403:Test_403();
			break;
		case 501:Test_501();
			break;
		case 502:Test_502();
			break;
		case 1:
			system("cls");
			Display_Menu();
			break;
		case 0: 
			break;
		}
		system("pause");
		system("cls");
	}
	printf("Test end.Press any key to exit.\n");
}
コード例 #16
0
int 
main(int argc, char *argv[])
{
    if (argc != 3)
    {
        printf("%s serverhost serverport\n", argv[0]);
        exit(0);
    }
    int port = atoi(argv[2]);
    // init server
    //
    InitServer(argv[1], port);
}
コード例 #17
0
SYSSTATUS CMainApp::InitInstance()
{
	CoInitialize(NULL);
	if (InitServer(8070)!=0) 
	{
		the_log.LogT(8, "InitInstance: Failed to init server on port 8070\n");
		return STATUS_UNSUCCESSFUL;
	}
	the_log.LogT(2, "InitInstance: DONE\n");
	//the_log.SetLogFile("c:\log.txt");
	OnStartup();
	return STATUS_SUCCESS;
}
コード例 #18
0
ファイル: XnSensorServer.cpp プロジェクト: 02031991/Sensor
XnStatus XnSensorServer::Run()
{
	//Initialize server
	XnStatus nRetVal = InitServer();

	if (nRetVal == XN_STATUS_OK)
	{
		//Initialization succeeded - run main loop
		nRetVal = ServerMainLoop();
	}

	Free();
	
	return nRetVal;
}
コード例 #19
0
ファイル: Server.cpp プロジェクト: Cephas1982/SomeGame
C_Server::C_Server()
{
	m_serverActive = true;
	m_totalConnections = 1;
	
	//setup the network info struct
	s_netInfo.maxConnections = 4;
	s_netInfo.playerCount = m_totalConnections;
	for(int i = 0; i < s_netInfo.maxConnections; i++)
		s_netInfo.playerName[i] = "";

	if(m_serverActive){
		InitServer();
	}//endif	

	
}
コード例 #20
0
ファイル: novnlm.c プロジェクト: pavanvunnava/open-watcom-v2
const char *RemoteLink( const char *parms, bool server )
{
    unsigned    i;


    _DBG_IPX(("RemoteLink\r\n"));
    server = server;
    if( *parms == '\0' )
        parms = "NovLink";
    for( i = 0; i < 48 && *parms != '\0'; ++parms ) {
        if( strchr( "/\\:;,*?+-", *parms ) == NULL ) {
            SAPStruct.ASServerIDpacket.serverName[ i++ ] = toupper( *parms );
        }
    }
    SAPStruct.ASServerIDpacket.serverName[ i ] = '\0';
    if( CIPXOpenSocketRTag( &SPXSocket, SocketTag ) != 0 ||
            CIPXOpenSocketRTag( &IPXSocket, SocketTag ) != 0 ) {
        return( TRP_ERR_can_not_obtain_socket );
    }

    _INITIPXECB( Serv );
    _INITIPXECB( Resp );
    RespECB.fragmentCount = 2;
    /* for SPXSocket - yes, SPXSocket is a long, but it always goes out on
        the wire as a 16-bit quantity */
    RespECB.fragmentDescriptor[1].size = sizeof( WORD );

    Timer.TCallBackProcedure = (void (*)(LONG))Ticker;
    Timer.TCallBackEBXParameter = (LONG)&Timer;
    Timer.TCallBackWaitTime = 0;
    Timer.TResourceTag = TimerTag;
    CScheduleInterruptTimeCallBack( &Timer );


    if( FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_server_name_already_in_use );
    }
    if( !InitServer() ) {
        RemoteUnLink();
        return( TRP_ERR_can_not_initialize_server );
    }
    return( NULL );
}
コード例 #21
0
ファイル: cf-testd.c プロジェクト: kkaempf/core
int CFTestD_StartServer(CFTestD_Config *config)
{
    int ret = -1;

    bool tls_init_ok = ServerTLSInitialize(config->priv_key, config->pub_key, &(config->ssl_ctx));
    if (!tls_init_ok)
    {
        return -1;
    }

    int sd = InitServer(CFTESTD_QUEUE_SIZE, config->address);

    int selected = 0;
    while (!TERMINATE && (selected != -1))
    {
        selected = WaitForIncoming(sd, WAIT_CHECK_TIMEOUT);

        if (selected > 0)
        {
            Log(LOG_LEVEL_DEBUG, "select(): %d", selected);
            CFTestD_AcceptAndHandle(sd, config);
        }
    }
    if (!TERMINATE)
    {
        Log(LOG_LEVEL_ERR,
            "Error while waiting for connections. (select: %s)",
            GetErrorStr());
    }
    else
    {
        ret = 0;
    }

    Log(LOG_LEVEL_NOTICE, "Cleaning up and exiting...");
    if (sd != -1)
    {
        Log(LOG_LEVEL_VERBOSE, "Closing listening socket");
        cf_closesocket(sd);
    }

    return ret;
}
コード例 #22
0
ファイル: novos2.c プロジェクト: Ukusbobra/open-watcom-v2
char *RemoteLink( char *name, bool server )
{
    unsigned    i;

    server = server;
putstring( "RemoteLink\r\n" );

    if( name == NULL || *name == '\0' )
        name = "NovLink";
    for( i = 0; i < 47 && *name != '\0'; ++name ) {
        if( strchr( "/\\:;,*?+-", *name ) == NULL ) {
            SAPHead.name[ i++ ] = toupper( *name );
        }
    }
    SAPHead.name[ i ] = '\0';
    if( SpxOpenSocket( &SPXSocket ) != 0 || IpxOpenSocket( &IPXSocket ) != 0 ) {
        return( TRP_ERR_can_not_obtain_socket );
    }
    _INITIPXECB( Serv );
    _INITIPXECB( Resp );
    RespECB.fragCount = 2;
    RespECB.fragList[1].fragSize = sizeof( WORD ); /* for SPXSocket */
#ifdef SERVER
    if( FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_server_name_already_in_use );
    }
    if( !InitServer() ) {
        RemoteUnLink();
        return( TRP_ERR_can_not_initialize_server );
    }
#else
    if( !FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_no_such_server );
    }
#endif
    return( NULL );
}
コード例 #23
0
ファイル: novnt.c プロジェクト: NoSuchProcess/open-watcom-v2
const char *RemoteLink( const char *parms, bool server )
{
    unsigned    i;
    WSADATA     data;
#ifdef SERVER
    const char  *p;
#endif

    server = server;

    if( *parms == '\0' )
        parms = "NovLink";
    for( i = 0; i < 47 && *parms != '\0'; ++parms ) {
        if( strchr( "/\\:;,*?+-", *parms ) == NULL ) {
            ServerName[ i++ ] = (char)toupper( *(byte *)parms );
        }
    }
    ServerName[ i ] = '\0';
    if( WSAStartup( 0x101, &data ) != 0 ) {
        return( TRP_ERR_can_not_obtain_socket );
    }
#ifdef SERVER
    if( FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_server_name_already_in_use );
    }
    if( (p = InitServer()) != NULL ) {
        RemoteUnLink();
        return( p );
    }
#else
    if( !FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_no_such_server );
    }
#endif
    return( NULL );
}
コード例 #24
0
int main(int argc, char**argv)
{
	printf("\n\n------- PROJECT IRI --- RADIOACTIVE GANGSTERS -------\n\n");

	// no need to save the unsubscribe ticket
	(void)subscribe(&console);
	if(InitServer(argc, (char const*const*const)argv) != EXIT_SUCCESS)
	{
		Log(LOGT_SERVER, LOGL_ERROR, "Failed to initialize!");
		return EXIT_FAILURE;
	}

	Rest(10); //10 seconds
	
	if(StartServer() != EXIT_SUCCESS)
	{
		Log(LOGT_SERVER, LOGL_ERROR, "Failed to start secondary operators!");
		return EXIT_FAILURE;
	}

	while(1)
	{	
		switch(getchar())
		{
			case 114: //r  
				resetNextAlarm();
				break;
			
			case 120: //x
				Log(LOGT_SERVER, LOGL_SYSTEM_ACTIVITY, "Server shutting down..");
				return EXIT_SUCCESS;
				break;
		}
	}

	return EXIT_SUCCESS;
}
コード例 #25
0
ファイル: iocpserver.cpp プロジェクト: doug-dicks/code-1
//---------------------------------------------------------------------------------------------------------------------------
//Init()
//-1 - error , 0 - ok
//ConnectThread -- thread number for connect
//ListenThread -- thread number for listen
//bAdoConnect -- use ado class?
//szConnect -- ado connection string
//---------------------------------------------------------------------------------------------------------------------------
int CIocpServer::Init(int connect_thread,int listen_thread,int adoflag,char *adostring)
{
	int irc=0;
	if(m_Inited)
	{
		fprintf(stderr, "初始化过一次了!\n");
		return -1;
	}

	WSADATA          wsd;
	// Load Winsock
	if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) 
	{
		fprintf(stderr, "unable to load Winsock!\n");
		return -1;
	}

	m_Inited = true;
	m_CLThreads = connect_thread;
	m_Threads = listen_thread;
	m_bAdo = adoflag;
	if(adostring!=NULL)
		m_szAdo = adostring;

	if(m_CLThreads > 0)
	{
		irc = InitClient(m_CLThreads);
		if(irc != 0)
			return irc;
	}

	if(m_Threads > 0)
		irc = InitServer(m_Threads);


	return irc;
}
コード例 #26
0
ファイル: trans1.c プロジェクト: zhiliang729/ctest
int main(int argc, char *argv[])
{
	int nSock, nSize, i, nPort;
	char szBuf[8096];
	ASSERT(GetShm() == 0);						/* 打开或创建共享内存 */
	ASSERT(GetConfig() == 0);					/* 读入配置信息到共享内存中 */
	ASSERT(GetConfigValue("./config.ini", "LOCAL", "UDPPORT", &nPort, STRINT) == 0);										/* 获取UDP服务端口号 */
	ASSERT(CreateUdpSock(&nSock, nPort) == 0);	/* 创建UDP套接字 */
	ASSERT(InitServer() == 0);					/* 进程转后台服务 */
	while (1)
	{
		memset(szBuf, 0, sizeof(szBuf));
		nSize = sizeof(szBuf);
		RecvMsgByUdp(nSock, szBuf, &nSize);		/* 接收主机进程监控信息 */
		PrintLog(stderr, szBuf);
		for (i=0; i<*pTopDesk; i++)
		{
			if (pDesk[i].nActive == 1) 
			{
				SendMsgByUdp(szBuf, nSize, pDesk[i].szIp, pDesk[i].nPort);
			}
		}
	}
}
コード例 #27
0
ファイル: server_threads.cpp プロジェクト: MLDL/lightlda
	void *ServerThreads::ServerThreadMain(void *thread_id){
		//long long maskLL = 0;
		//maskLL |= (1LL << 21);
		//DWORD_PTR mask = maskLL;
		//SetThreadAffinityMask(GetCurrentThread(), mask);
		int32_t my_id = *(reinterpret_cast<int32_t*>(thread_id));

		ThreadContext::RegisterThread(my_id);
		REGISTER_THREAD_FOR_STATS(false);

		// set up thread-specific server context
		SetUpServerContext();
		SetUpCommBus();
		pthread_barrier_wait(&aggregator_barrier);
		int32_t sender_id;
		zmq::message_t zmq_msg_aggregator;
		(comm_bus_->*CommBusRecvAny)(&sender_id, &zmq_msg_aggregator);
		MsgType msg_type = MsgBase::get_msg_type(zmq_msg_aggregator.data());
		if (msg_type == kAggregatorConnect) {
			AggregatorConnectMsg msg(zmq_msg_aggregator.data());
			int32_t aggregator_id = msg.get_aggregator_id();
			if (sender_id != my_id + 1 || sender_id != aggregator_id)
			{
				LOG(FATAL) << "Aggregator thread ID should be server thread id + 1";
			}
		}
		else
		{
			LOG(FATAL) << "Server thread expects aggregator thread to connect";
		}

		pthread_barrier_wait(&init_barrier);

		InitServer();

		zmq::message_t zmq_msg;
		//int32_t sender_id;
		//MsgType msg_type;
		void *msg_mem;
		bool destroy_mem = false;
		while (1) {
			CommBusRecvAnyWrapper(&sender_id, &zmq_msg);

			msg_type = MsgBase::get_msg_type(zmq_msg.data());
			//VLOG(0) << "msg_type = " << msg_type;
			destroy_mem = false;

			if (msg_type == kMemTransfer) {
				MemTransferMsg mem_transfer_msg(zmq_msg.data());
				msg_mem = mem_transfer_msg.get_mem_ptr();
				msg_type = MsgBase::get_msg_type(msg_mem);
				destroy_mem = true;
			}
			else {
				msg_mem = zmq_msg.data();
			}

			switch (msg_type)
			{
			case kClientShutDown:
			{
									VLOG(0) << "get ClientShutDown from bg " << sender_id;
									bool shutdown = HandleShutDownMsg();
									if (shutdown) {
										VLOG(0) << "Server shutdown";
										// client_delta_queue_.Exit();
										comm_bus_->ThreadDeregister();
										FINALIZE_STATS();
										return 0;
									}
									break;
			}
		
				// NOTE(v-feigao): add handler of kClientModelSliceRequest msg
			case kClientModelSliceRequest: {
											   VLOG(0) << "Received ModelSliceRequest Msg!";
											   ClientModelSliceRequestMsg model_slice_request_msg(msg_mem);
											   HandelModelSliceRequest(sender_id, model_slice_request_msg);
											   break;
			}

				// NOTE(jiyuan): add handle of the kClientSendOpLogIteration msg
			case kClientSendOpLogIteration:
			{
											  /*
											  VLOG(0) << "Received OpLogIteration Msg!";
											  ClientSendOpLogIterationMsg client_send_oplog_iteration_msg(msg_mem);
											  TIMER_BEGIN(0, SERVER_HANDLE_OPLOG_MSG);
											  HandleOpLogIterationMsg(sender_id, client_send_oplog_iteration_msg);
											  TIMER_END(0, SERVER_HANDLE_OPLOG_MSG);
											  */

											  // forward the message to AggregatorThread by inserting the message to a queue

											  // server_push_oplog_iteration_msg does not own the memory
											  ClientSendOpLogIterationMsg client_send_oplog_iteration_msg(msg_mem);
											  //size_t msg_size = server_push_oplog_iteration_msg.get_size();

											  // get the available size of the arbitrary message
											  size_t avai_size = client_send_oplog_iteration_msg.get_avai_size();

											  // create a new msg with the same size as server_push_oplog_iteration_msg
											  std::unique_ptr<ClientSendOpLogIterationMsg> msg_ptr(new ClientSendOpLogIterationMsg(avai_size));

											  // copy the server_push_oplog_iteration_msg to new msg
											  msg_ptr->get_table_id() = client_send_oplog_iteration_msg.get_table_id();
											  msg_ptr->get_is_clock() = client_send_oplog_iteration_msg.get_is_clock();
											  msg_ptr->get_client_id() = client_send_oplog_iteration_msg.get_client_id();
											  msg_ptr->get_iteration() = client_send_oplog_iteration_msg.get_iteration();
											  msg_ptr->get_is_iteration_clock() = client_send_oplog_iteration_msg.get_is_iteration_clock();
							
											  memcpy(msg_ptr->get_data(), client_send_oplog_iteration_msg.get_data(), avai_size);
											  VLOG(0) << "Server threads receive kClientSendOpLogIteration. iteration: " << msg_ptr->get_iteration()
												  << "is_clock = " << msg_ptr->get_is_clock() << " table id = " << msg_ptr->get_table_id();

											  // move the msg_ptr into the queue
											  // ORIG: client_delta_queue_.Push(std::move(msg_ptr));
											  client_delta_queue_.Push((msg_ptr));

											  break;
			}
				// v-feigao: add Handler of kServerPushOpLogIteration 
				// Aggregator thread transfer this msg to server, server then send it out.
			case kServerPushOpLogIteration:
			{
											  ServerPushOpLogIterationMsg server_push_msg(msg_mem);
											  int32_t bg_id = server_push_msg.get_bg_id();
											  size_t sent_size = comm_bus_->Send(bg_id, server_push_msg.get_mem(), server_push_msg.get_size());
											  CHECK_EQ(sent_size, server_push_msg.get_size());
											  VLOG(0) << "Server Thread send push msg. Iteration: " << server_push_msg.get_iteration();
			}
				break;
			case kServerUpdateClock: {
										 ServerUpdateClockMsg server_update_clock_msg(msg_mem);
										 for (int32_t i = 0; i < GlobalContext::get_num_clients(); ++i) {
											 int32_t bg_id = GlobalContext::get_head_bg_id(i);
											 size_t sent_size = comm_bus_->Send(
												 bg_id, server_update_clock_msg.get_mem(), server_update_clock_msg.get_size());
											 CHECK_EQ(sent_size, server_update_clock_msg.get_size());
											 VLOG(0) << "Server Thread send Init Update Clock msg. ";
										 }
										 break;
			}
			default:
				LOG(FATAL) << "Unrecognized message type " << msg_type;
			}

			if (destroy_mem)
				MemTransfer::DestroyTransferredMem(msg_mem);
		}
	}
コード例 #28
0
ファイル: main.cpp プロジェクト: SKplanet/RemoteTestService
int main(int argc, char* argv[])
{
	/*
	pid_t childPID;
	g_forcefbmode = false;
	if( argc > 1 && strcmp(argv[1], "fb")==0)
		g_forcefbmode = true;

	childPID = fork();

	if( childPID >= 0 )
	{
		if( childPID == 0 ) // child process
		{
			Log("\n Child Activated\n");
		    //--- fb initialize
		    if( init_framebuffer() == 0 ) {
		        Err("init framebuffer failed\n");
		        return 0;
		    }
		    Log("Surfaceflinger initialized.\n");

			Log("\n Child Activated - init server\n");
		    InitServer(); // endless loop
		}
		else
		{
			sleep(3);
			Log("\n Launch Process succeeded\n");
		}
	}
	*/

	fprintf(stderr,"%s\n", RUISVC_VERSION);


	g_forcefbmode = false;
	if( argc > 1 && strcmp(argv[1], "fb")==0)
		g_forcefbmode = true;

	if( argc > 1 && strcmp(argv[1], "verbose")==0)
		LogEnable(1);

	signal (SIGHUP, SIG_IGN);

    //--- fb initialize
    if( init_framebuffer() == 0 ) {
        Err("init framebuffer failed\n");
        return 0;
    }
    Log("Surfaceflinger initialized.\n");

    InitServer(); // endless loop


    // --- never come here
    /*
    int cnt = 0;
    while(1) {
        sleep(1);
        Log("%04d:Idle\n",cnt++);
    }

    //--- exit
    if( exit_framebuffer() == 0 ) {
        Err("exit framebuffer failed\n");
        return 0;
    }

    Log("Framebuffer Exit.\n");
	*/

    fprintf(stderr,"BYE\n");
    return true;
}
コード例 #29
0
// Server (Data source)
CodeTorrent::CodeTorrent(int in_field_size, int in_num_blocks_per_gen, int in_block_size,
			 const char *in_filename, int in_fileSize, bool dummy) {

        InitServer(in_field_size, in_num_blocks_per_gen, in_block_size, in_filename, in_fileSize, false);
	nc = new NC(field_size, is_sim);
}
コード例 #30
0
ファイル: novdos.c プロジェクト: Azarien/open-watcom-v2
const char *RemoteLink( const char *parms, bool server )
{
    unsigned    i;
    BYTE        major_ver,minor_ver;
    WORD        max_conn,avail_conn;

    #ifdef __WINDOWS__
    {
        HINSTANCE       ipxspx;
        HINSTANCE       netapi;
        HMODULE         netware;

        GlobalPageLock( (HGLOBAL)FP_SEG( &SAPECB ) );
        netware = GetModuleHandle( "NETWARE.DRV" );
        ipxspx = LoadLibrary( "NWIPXSPX.DLL" );
        netapi = LoadLibrary( "NWCALLS.DLL" );
        if( (UINT)ipxspx < 32 ) return( TRP_ERR_IPX_SPX_not_present );
        if( (UINT)netapi < 32 ) return( TRP_ERR_Netware_API_not_present );
        if( netware == NULL ) return( TRP_ERR_NETWAREDRV_not_present );
#define str( x ) #x
#define GetAddr( hdl, x ) IPXFuncs[x] = (NOVWINAPI)GetProcAddress( hdl, str( x ) )
#define GetIPXAddr( x ) GetAddr( ipxspx, x )
        GetAddr( netapi, NWReadPropertyValue );
        GetIPXAddr( IPXInitialize );
        GetIPXAddr( IPXSPXDeinit );
        GetIPXAddr( IPXCancelEvent );
        GetIPXAddr( IPXCloseSocket );
        GetIPXAddr( IPXDisconnectFromTarget );
        GetIPXAddr( IPXGetInternetworkAddress );
        GetIPXAddr( IPXGetIntervalMarker );
        GetIPXAddr( IPXGetLocalTarget );
        GetIPXAddr( IPXListenForPacket );
        GetIPXAddr( IPXOpenSocket );
        GetIPXAddr( IPXRelinquishControl );
        GetIPXAddr( IPXScheduleIPXEvent );
        GetIPXAddr( IPXSendPacket );
        GetIPXAddr( SPXAbortConnection );
        GetIPXAddr( SPXEstablishConnection );
        GetIPXAddr( SPXInitialize );
        GetIPXAddr( SPXListenForConnection );
        GetIPXAddr( SPXListenForSequencedPacket );
        GetIPXAddr( SPXSendSequencedPacket );
        GetIPXAddr( SPXTerminateConnection );
        IPXTaskID = 0x00000000L;
        if( IPXInitialize( (DWORD __far *)&IPXTaskID, 20, 576 ) != 0 ) {
            return( TRP_ERR_IPX_not_initialized );
        }
    }
    #endif
    server = server;
    if( *parms == '\0' )
        parms = DefLinkName;
    for( i = 0; i < MAX_NAME_LEN && *parms != '\0'; ++parms ) {
        if( strchr( "/\\:;,*?+-", *parms ) == NULL ) {
            SAPHead.name[ i++ ] = toupper( *parms );
        }
    }
    SAPHead.name[ i ] = '\0';
    if( !_SPXInitialize( 20, 576, &major_ver, &minor_ver, &max_conn, &avail_conn ) ) {
        return( TRP_ERR_SPX_not_present );
    }
    if( _IPXOpenSocket( &SPXSocket, 0 ) != 0 || _IPXOpenSocket( &IPXSocket, 0 ) != 0 ) {
        return( TRP_ERR_can_not_obtain_socket );
    }
    _INITIPXECB( Serv );
    _INITIPXECB( Resp );
    RespECB.fragmentCount = 2;
    RespECB.fragmentDescriptor[1].size = sizeof( WORD ); /* for SPXSocket */
#ifdef SERVER
    if( FindPartner() ) {
        RemoteUnLink();
        return( TRP_ERR_server_name_already_in_use );
    }
    if( !InitServer() ) {
        RemoteUnLink();
        return( TRP_ERR_can_not_initialize_server );
    }
#else
    if( FindPartner() == 0 ) {
        RemoteUnLink();
        return( TRP_ERR_no_such_server );
    }
#endif
    return( NULL );
}