aeServer* aeServerCreate( char* ip,int port ) { aeServer* serv = (aeServer*)zmalloc( sizeof(aeServer )); serv->runForever = startServer; serv->send = sendMessageToReactor; serv->close = sendCloseEventToReactor; serv->sendToClient = anetWrite; serv->closeClient = freeClient; serv->listen_ip = ip; serv->port = port; serv->connectNum = 0; serv->reactorNum = 2; serv->workerNum = 3; serv->maxConnect = 1024; serv->connlist = shm_calloc( serv->maxConnect , sizeof( aeConnection )); serv->reactorThreads = zmalloc( serv->reactorNum * sizeof( aeReactorThread )); serv->workers = zmalloc( serv->workerNum * sizeof(aeWorkerProcess)); serv->mainReactor = zmalloc( sizeof( aeReactor )); serv->mainReactor->eventLoop = aeCreateEventLoop( 10 ); aeSetBeforeSleepProc( serv->mainReactor->eventLoop ,initOnLoopStart ); //安装信号装置 installMasterSignal( serv ); servG = serv; return serv; }
void initServer( appnetServer *serv ) { serv->connlist = shm_calloc( serv->connect_max , sizeof(appnetConnection) ); serv->reactor_threads = zmalloc( serv->reactor_num * sizeof(appnetReactorThread) ); serv->workers = zmalloc( ( serv->worker_num + serv->task_worker_num ) * sizeof(appnetWorkerProcess) ); serv->worker_pipes = zmalloc( ( serv->worker_num + serv->task_worker_num ) * serv->reactor_num * sizeof(appnetWorkerPipes) ); srand( (unsigned) time( NULL ) ); serv->main_reactor = zmalloc( sizeof(appnetReactor) ); serv->main_reactor->event_loop = aeCreateEventLoop( 10 ); aeSetBeforeSleepProc( serv->main_reactor->event_loop , initOnLoopStart ); installMasterSignal( serv ); }