1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| if (remote[i].events & EPOLLOUT) { while (sendSize < totalSize) { result = send(sock, postData, min(postDataBufSize, totalSize - sendSize), 0); if (-1 == result) { if (errno != EAGAIN && errno != EINTR) { goto end; } else if (!iter->second.eagain) { iter->second.eagain = true; } break; } if (iter->second.eagain) { sendSize += result; } iter->second.sendSize += result; } if (sendSize >= totalSize) { struct epoll_event event = {0}; event.data.fd = sock; event.events = EPOLLIN | EPOLLERR | EPOLLET; epoll_ctl(epollFd, EPOLL_CTL_MOD, sock, &event); } } if (remote[i].events & EPOLLIN) { iter = connMap.find(sock); assert(iter != connMap.end()); result = recv(sock, recvBuf, sizeof(recvBuf), 0); if (0 == result || (-1 == result && errno != EAGAIN && errno != EINTR)) { printf("socket(%d) error = %s\n", sock, strerror(errno)); } printf("socket(%d) recv %s\n", sock, recvBuf); memset(recvBuf, 0, sizeof(recvBuf)); goto end; } if (remote[i].events & EPOLLERR) { printf("socket(%d) error = %s\n", sock, strerror(errno)); iter = connMap.find(sock); goto end; } continue; end: epoll_ctl(epollFd, EPOLL_CTL_DEL, sock, NULL); close(sock); connMap.erase(iter);
|