linux下 各类tcp网络服务器的实现源代码.doc
还剩
25页未读,
继续阅读
下载文档到电脑,马上远离加班熬夜!
亲,喜欢就下载吧,价低环保!
内容要点:
%s", sock, GetCurrentTime(0, 0));close(sock);return -1;}else i += ret;}sprintf(errorMessage, "Recv socket:%d recv() OK! %d/%d bytes received! %s", sock, i, size, GetCurrentTime(0, 0));return i;}最 后需要 tival.tv_usec = 0;FD_ZERO(&readfds);if(sock > 0) {FD_SET(sock, &readfds);maxfds=((sock > maxfds)?sock:maxfds);}else {sprintf(errorMessage, "Recv socket:%d error! return:-2 %s", sock, GetCurrent sprintf(errorMessage, "Send socket:%d send() OK! %d/%d bytes sent! %s", sock, i, size, GetCurrentTime(0, 0));return i;}/*----------------------源代码代码结束 --------------------------------------------* sprintf(errorMessage, "Send socket:%d error! return:-2 %s", sock, GetCurrentTime(0, 0));return -2;}ret = select(maxfds + 1, NULL, &writefds, NULL, &tival);if(ret <= 0) {if(ret < 0) sprintf(/*----------------------源代码代码开始 --------------------------------------------*/intSend(int sock, char * buf, size_t size, int flag, int timeout) {/************************* 关于本函数******************** struct sockaddr_in sin;struct hostent *he;if((he=gethostbyname(serverip))== 0) {sprintf(errorMessage, "ConnectSCPServer IP address '%s' error! return:-1 %s", serverip, GetCurrentTime(0, 0));ret if(ret < 0) {sprintf(errorMessage, "OpenTCPServer listen() error! return:%d, errno=%d, errortext:'%s' %s", ret, errno, strerror(errno), GetCurrentTime(0, 0));close(sockfd);return -6;}sprintf(er ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuseORnot, sizeof(int));if(ret < 0) {sprintf(errorMessage, "OpenTCPServer setsockopt() reuse error! return:%d, errno=%d, errortext:'%s' %s",
发表评论
暂无评论,赶快抢占沙发吧。