int RTIP_SOCKETS_Driver::Listen( SOCK_SOCKET socket, int backlog ) { int ret; ret = rtp_net_listen ((RTP_HANDLE) socket, backlog); return ret; }
/* ============== ============== */ void rtsmb_srv_net_init (void) { RTSMB_STATIC PNET_THREAD tempThread; #if (CFG_RTSMB_PRINT_SIZES) char buffer[128]; rtp_sprintf (buffer, "net thread: %i\n", sizeof (NET_THREAD_T)); tm_puts (buffer); #endif #if INCLUDE_RTSMB_DC next_pdc_find = rtp_get_system_msec () + rtsmb_srv_net_pdc_next_interval (); #endif /** * You will note that we consistently use the term 'thread' to refer to the 'mainThread.' * In fact, it is not a full blown thread, but is only treated the same, for coding simplicity * purposes. This first thread always runs in the same thread/process as the caller of our API * functions. If CFG_RTSMB_MAX_THREADS is 0, no threads will ever be created. */ tempThread = rtsmb_srv_net_thread_new (); /* this will succeed because there is at least one thread free at start */ if (!tempThread) { RTSMB_DEBUG_OUTPUT_STR("rtsmb_srv_net_init: Error -- could not allocate main pseudo-thread.\n", RTSMB_DEBUG_TYPE_ASCII); return; } mainThread = tempThread; rtsmb_srv_net_thread_init (mainThread, 0); /* -------------------- */ /* get the three major sockets */ /* Name Service Datagram Socket */ if (rtsmb_net_socket_new (&net_nsSock, rtsmb_nbns_port, FALSE) < 0) { rtp_printf(("Could not allocate Name & Datagram service socket\n")); } /* SSN Reliable Socket */ #ifdef RTSMB_ALLOW_SMB_OVER_TCP if (rtsmb_net_socket_new (&net_ssnSock, rtsmb_nbss_direct_port, TRUE) < 0) { rtp_printf(("Could not allocate Name & Datagram service socket\n")); } #else if (rtsmb_net_socket_new (&net_ssnSock, rtsmb_nbss_port, TRUE) < 0) { rtp_printf (("Could not allocate SSN Reliable socket\n")); } #endif if (rtp_net_listen ((RTP_SOCKET) net_ssnSock, prtsmb_srv_ctx->max_sessions) != 0) { RTSMB_DEBUG_OUTPUT_STR("Error occurred while trying to listen on SSN Reliable socket.\n", RTSMB_DEBUG_TYPE_ASCII); } if (rtp_net_setbroadcast((RTP_SOCKET) net_nsSock, 1) < 0) { RTSMB_DEBUG_OUTPUT_STR("Error occurred while trying to set broadcast on Name & Datagram service socket\n", RTSMB_DEBUG_TYPE_ASCII); } }
int HTTP_ServerInit (HTTPServerContext *server, /** pointer to uninitialized \Ref{HTTPServerContext} struct */ const HTTP_CHAR *name, /** Server name. Sent in HTTP header. */ const HTTP_CHAR *rootDir, /** Path to the root directory for content. */ const HTTP_CHAR *defaultFile, /** Default Filename if "\" or "path\" is passed with no file name. */ HTTP_INT8 httpMajorVersion, /** Normally 1 for HTTP 1.1 */ HTTP_INT8 httpMinorVersion, /** Normally 1 for HTTP 1.1 */ HTTP_UINT8 *ipAddr, /** V4/V6 examples: ipaddr[4] = {192, 168, 0, 6}; ipAddr = "fe80::20b:dbff:fe2f:c162"; */ HTTP_INT16 port, /** port number (80) usually */ HTTP_INT16 ipType, /** ipversion 4 or 6 */ HTTP_BOOL allowKeepAlive, /** If HTTP version < 1.1 enables keep-alive support. For 1,1 and greater keep-alive is the default.*/ HTTPServerConnection* connectCtxArray, /** pointer to uninitialized bytes, must be (sizeof(HTTPServerConnection) * maxConnections)) bytes. */ HTTP_INT16 maxConnections, /** The maximum limit on simultaneous HTTP server connections */ HTTP_INT16 maxHelperThreads /** If HTTP_SERVER_MULTITHREAD is defined, the max number of helper threads to spawn */ ) { rtp_memset((unsigned char *) server, 0, sizeof(HTTPServerContext)); if (rtp_net_socket_stream_dual(&server->serverSocket, ipType) >= 0) { if (rtp_net_bind_dual(server->serverSocket, RTP_NET_STREAM, ipAddr, port, ipType) >= 0 && rtp_net_listen(server->serverSocket, maxConnections) >= 0) { if (!ipAddr) { if (rtp_net_getsockname(server->serverSocket, server->serverAddress.ipAddr, &server->serverAddress.port, &server->serverAddress.type) < 0) { rtp_memset(server->serverAddress.ipAddr, 0, RTP_NET_IP_ALEN); } } else { rtp_memcpy(server->serverAddress.ipAddr, ipAddr, RTP_NET_IP_ALEN); server->serverAddress.port = port; } if (name) { rtp_strncpy(server->serverName, name, HTTP_SERVER_NAME_LEN-1); } else { rtp_strncpy(server->serverName, HTTP_SERVER_NAME_STRING, HTTP_SERVER_NAME_LEN-1); } server->httpMajorVersion = httpMajorVersion; server->httpMinorVersion = httpMinorVersion; if (rootDir) { rtp_strncpy(server->rootDir, rootDir, HTTP_SERVER_PATH_LEN-1); } else { /* default to the current working directory */ server->rootDir[0] = '.'; server->rootDir[1] = 0; } if (defaultFile) { rtp_strncpy(server->defaultFile, defaultFile, HTTP_SERVER_DEFAULT_FILE_LEN-1); } else { rtp_strncpy(server->defaultFile, HTTP_SERVER_DEFAULT_FILE, HTTP_SERVER_DEFAULT_FILE_LEN-1); } if (!allowKeepAlive || (server->httpMajorVersion == 1 && server->httpMinorVersion > 0) || (server->httpMajorVersion > 1)) { server->allowKeepAlive = allowKeepAlive; server->maxConnections = maxConnections; DLLIST_INIT(&server->pathList); DLLIST_INIT(&server->realmList); server->allowedClientList = 0; server->numAllowedClients = 0; server->blockedClientList = 0; server->numBlockedClients = 0; #ifdef HTTP_SERVER_KEEP_ALIVE DLLIST_INIT(&server->openConnections); #endif /* HTTP_SERVER_KEEP_ALIVE */ #ifdef HTTP_SERVER_MULTITHREAD server->connectionContextArray = connectCtxArray; server->maxHelperThreads = maxHelperThreads; /* allocate the server lock */ if (rtp_sig_mutex_alloc(&server->lock, 0) >= 0) { RTP_MUTEX helperThreadMutex; RTP_SEMAPHORE helperThreadSemaphore; /* initialize the session queue */ if (rtp_sig_mutex_alloc(&helperThreadMutex, 0) >= 0) { if (rtp_sig_semaphore_alloc(&helperThreadSemaphore, 0) >= 0) { if (rtp_helper_thread_ctx_init ( &server->helperContext, helperThreadMutex, helperThreadSemaphore ) >= 0) { int n; // initialize the free job list server->jobFreeList = connectCtxArray; for (n = 0; n < maxConnections-1; n++) { connectCtxArray[n].job.next = &(connectCtxArray[n+1].job); connectCtxArray[n].job.execute = _HTTP_ServerExecuteJob; connectCtxArray[n].server = server; } connectCtxArray[n].job.next = 0; connectCtxArray[n].job.execute = _HTTP_ServerExecuteJob; connectCtxArray[n].server = server; server->status = HTTP_SERVER_INITIALIZED; return (0); } rtp_sig_semaphore_free(helperThreadSemaphore); } rtp_sig_mutex_free(helperThreadMutex); } rtp_sig_mutex_free(server->lock); } #else /* HTTP_SERVER_MULTITHREAD */ //server->queueFirst = 0; //server->queueLast = 0; server->status = HTTP_SERVER_INITIALIZED; return (0); #endif /* HTTP_SERVER_MULTITHREAD */ } } rtp_net_closesocket(server->serverSocket); } return (-1); }