int process_clsr(){ int ret; int free_no; char buff[1024]; //T_MESSAGE_QUEUE_FMT mbuff; T_CLIENT_REQUEST req; //受信処理 if ( tcpSelect(l_server_fd,0,G_ConfTbl->select_timeout) != 1 ){ return 0; } l_client_fd=tcpAccept(l_server_fd); logPrint(DEBUG_DEBUG,"tcpAccept(%d) => %d",l_server_fd,l_client_fd); if ( l_client_fd == 0 ){ return 0; } //クライアント要求をタスクに割り振る free_no=cacheGetFreeTaskNo(); if ( free_no < 0 ){ logPrint(DEBUG_WARNING,"task is busy (no slot)"); tcpClose(l_client_fd); return 0; } sprintf(l_sock_file,"%s/ud%03d.sock",G_TempDir,free_no); l_gate_fd=udConnect(l_sock_file); ret=udSend(l_gate_fd, l_client_fd, &req, sizeof(req),G_ConfTbl->send_timeout); logPrint(DEBUG_DEBUG,"udSend(%d,%d,*,%d,%d) => %d", l_gate_fd, l_client_fd,sizeof(req),G_ConfTbl->send_timeout,ret); tcpClose(l_client_fd); return 0; }
static void ns_accept_connection(Dispatcher *dis, int fd, void *udata) { NS *ns = (NS *) dis; fd = tcpAccept(fd); ns_add_connection(ns, fd); if (ns->on_connect_cb) { ns->on_connect_cb(ns, fd, ns->on_connect_udata); } }
int fcgi_accept(int argc, char* argv[]) { // fprintf(stderr, "count = %d\n", ++count); if(!is_init) fcgi_init(argc, argv); close(STDIN_FILENO); close(STDOUT_FILENO); int connfd = tcpAccept(NEW_FCGI_LISTEN_FD); // fprintf(stderr, "connfd = %d\n", connfd); assert(connfd >= 0); setNonBlock(connfd, false); struct Buffer* input = newBuffer(); // fprintf(stderr, "before read\n"); int n = bufferRead(input, connfd); fprintf(stderr, "n = %d\n", n); // fprintf(stderr, "after read\n"); char* line; //init environment while( (line = readLine(input)) != NULL && line[0] != '\0') { if(strlen(line) > 0) { // fprintf(stderr, "%s\n", line); putenv(line); } } freeBuffer(input); dup2(connfd, STDIN_FILENO); dup2(connfd, STDOUT_FILENO); setbuf(stdin, NULL); setbuf(stdout, NULL); // fprintf(stderr, "fcgi accept over. \n"); return 0; }
int Net::serverExecute() { int i=0; printf("init done!\n"); int quit = 0; ipPeer.resolvehost("NULL", 9999); tcpOpen(); ipPeer.resolveIP(); printf("main loop\n"); while (running) { if (tcpAccept()) { tcpGetPeerAddress(); fprintf(stdout, "client connected:\n"); quit = 0; while (!quit) { if ((SDLNet_TCP_Recv(socketPeer, buffer, DIMBUFFER) > 0)) { fprintf(stdout, "reci:\t%s", buffer); snprintf(buffer, DIMBUFFER, "server123\t%d\n", i); tcpSend(socketPeer, buffer); fprintf(stdout, "send:\t%s", buffer); } // if ((strcmp(buffer, "exit") == 0)) { // fprintf(stdout, "session terminated\n"); // quit2 = 1; // } // if ((strcmp(buffer, "quit") == 0)) { // fprintf(stdout, "programm terminated\n"); // quit2 = 1; // quit = 1; // } // SDL_Delay(100); i++; } } SDL_Delay(100); } // SDLNet_TCP_Close(socketClient); cleanup(); return 0; }
Socket *socketAccept(Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort) { #if (TCP_SUPPORT == ENABLED) Socket *newSocket; //Make sure the socket handle is valid if(!socket) return NULL; //This function shall be used with connection-oriented socket types if(socket->type != SOCKET_TYPE_STREAM) return NULL; //Accept an incoming connection attempt newSocket = tcpAccept(socket, clientIpAddr, clientPort); //Return a handle to the newly created socket return newSocket; #else return NULL; #endif }
static void onAccept(struct Event* event, void* arg) { assert(event != NULL && arg != NULL); #ifdef DEBUG printf("accept a connection.\n"); #endif Server* server = (Server*)event->arg; int sockfd = server->sockfd; assert(sockfd >= 0); int connfd = tcpAccept(sockfd); assert(connfd >= 0); int nextId = server->nextId % server->nthreads; server->nextId++; offer(server->threads[nextId]->queue, connfd); int efd = server->threads[nextId]->efd; uint64_t count = 1; int n = write(efd, &count, sizeof(count)); assert(n == sizeof(count)); }
Socket* ServerSocket::accept() { return new Socket(tcpAccept()); }