//打开监听套接字,PASV模式下使用 static void ftp_nobody_listenfd(int fd,int* listenfd) { if(*listenfd == -1){ struct in_addr ip; ftp_get_local_ip(&ip); char ipstr[40] = {0}; inet_ntop(AF_INET,&ip,ipstr,sizeof(ipstr)); *listenfd = TcpServer(ipstr,20); } if(*listenfd == -1) ftp_ipc_send_msg(fd,FTP_OK,-1); else ftp_ipc_send_msg(fd,FTP_ERROR,-1); }
int main() { int listenfd = TcpServer("127.0.0.1", 8976); epoll_t et; epoll_init(&et, listenfd, &run); while(1) { epoll_loop(&et); epoll_handle_fd(&et); } //epoll_destroy(&et); close(et.epoll_fd_); close(listenfd); }
int main() { int mainserver; WORD sockVersion = MAKEWORD(2,2); WSADATA wsaData; if(WSAStartup(sockVersion, &wsaData)!=0) { return 0; } cout<<"mainserver?"<<endl; cin>>mainserver; TcpServer server = TcpServer(bool(mainserver)); server.runserver(); }
int main(int argc, char **argv) { if (argc < 4) { printf("\n\tUsage: %s <host> <port> <tcp|udp>\n\n", argv[0]); return 0; } set_sig_handler(SIGINT, int_handler); set_sig_handler(SIGURG, urg_handler); char *host = argv[1]; char *port = argv[2]; char *protocol = argv[3]; int server_socket = create_socket(protocol); if (server_socket == -1) { perror("create_socket() error"); return 0; } if (bind_socket(server_socket, host, atoi(port)) == -1) { perror("bind_socket() error"); close(server_socket); return 0; } bool is_tcp = !strcmp(protocol, "tcp"); if (is_tcp) TcpServer(server_socket); else UdpServer(server_socket); close(server_socket); return 0; }
enum MqErrorE pIoCreate ( struct MqS * const context, struct MqBufferLS * const alfa, struct MqIoS ** const out ) { struct MqIoS * const io = *out = (struct MqIoS *) MqSysCalloc (MQ_ERROR_PANIC, 1, sizeof (*io)); io->context = context; // parent and child get both this initial value // !!attention if child get an other value then it will wait forever (SysWait) // during child cleanup io->id.type = MQ_ID_UNUSED; io->config = &context->config.io; // search for communication type if (MQ_IS_PARENT (context)) { // init parent io->sockP = (MQ_SOCK *)&sockUndef; // create event-structure MqErrorCheck (pEventCreate (context, &io->event)); // create communication layer switch (io->config->com) { #if defined(MQ_IS_POSIX) case MQ_IO_UDS: MqErrorCheck (UdsCreate (io, &io->iocom.udsSP)); break; #endif case MQ_IO_TCP: MqErrorCheck (TcpCreate (io, &io->iocom.tcpSP)); break; case MQ_IO_PIPE: MqErrorCheck (PipeCreate (io, &io->iocom.pipeSP)); break; } } else { struct MqIoS * parent = context->config.parent->link.io; io->sockP = parent->sockP; // without "event" a client is not able to do any communication io->event = parent->event; } // reset fdset FD_ZERO (&io->fdset); // create the server socket if (MQ_IS_SERVER_PARENT (context)) { switch (io->config->com) { #if defined(MQ_IS_POSIX) case MQ_IO_UDS: MqErrorCheck (UdsServer (alfa, io->iocom.udsSP)); break; #endif case MQ_IO_TCP: MqErrorCheck (TcpServer (alfa, io->iocom.tcpSP)); break; case MQ_IO_PIPE: MqErrorCheck (PipeServer (io->iocom.pipeSP)); break; } } error: return MqErrorStack (context); }