标签:linux socket 线程 recvfrom errno
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> 偶然情况下recvfrom函数出现了不正常的情况,目前还没有复现。</span>
贴出部分的代码和日志问价里面的信息。
struct timeval tv_out; tv_out.tv_sec = 120; tv_out.tv_usec = 0; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out)); udp_media_cond = 1; while(udp_media_cond) { memset(buf, 0, sizeof(buf)); memset(temp, 0, sizeof(temp)); len = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&client_addr_from, &fromlen); if (0 >= len) { syslog(LOG_DEBUG, "DEBUG:recv data error!"); syslog(LOG_DEBUG, "DEBUG:uid is '%s', port is '%d'.", uid, port); if (EAGAIN == errno) { syslog(LOG_DEBUG, "DEBUG: EAGAIN!"); //return 0; } } buf[len] = '\0'; }
Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'. Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG: EAGAIN! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'. Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'. Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'. Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'.后面那个打印了十几W条
Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf rsyslogd-2177: imuxsock begins to drop messages from pid 2218 due to rate-limiting Oct 27 12:26:22 32f32c8c-8c75-4249-bbf2-afa068de9aaf rsyslogd-2177: imuxsock lost 176521 messages from pid 2218 due to rate-limiting
Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG: EAGAIN!是因为过了2分钟,没有收到任何数据。
狂打印
Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:16 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060110', port is '5500'.就是不正常的,除非开始接受数据,每次接受的数据为为空。
这个线程最后是死掉了,过了一段时候后
Oct 27 12:26:22 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:22 32f32c8c-8c75-4249-bbf2-afa068de9aaf rsyslogd-2177: imuxsock begins to drop messages from pid 2218 due to rate-limiting Oct 27 12:26:29 32f32c8c-8c75-4249-bbf2-afa068de9aaf rsyslogd-2177: imuxsock lost 3408 messages from pid 2218 due to rate-limiting Oct 27 12:26:29 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:recv data error! Oct 27 12:26:29 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG:uid is '00060001', port is '5501'. Oct 27 12:26:29 32f32c8c-8c75-4249-bbf2-afa068de9aaf server_debug:[2218]: DEBUG: EAGAIN!主线程收不到任何的数据,也有可能是客户端没有发送(可能性极小),该线程再也没有任何打印。
标签:linux socket 线程 recvfrom errno
原文地址:http://blog.csdn.net/u012377333/article/details/40513261