浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Reading socket is slow - C




while ((return_count = socket_read(socket_number, &receive_str[i], 5120)) > 0)
This will loop until the server closes the connection, which is exactly why it's taking your 30 to 45 seconds before it actually 'stops'. Webservers keep the connection with the client open for that long in case the client has more requests to send.
if(i > RECVSTRSIZE); The semicolon at the end of your line will make this if do 'nothing'.
Since by default most socket operations are blocking, I would suggest using select() to first check if there is actually something to read.

posted on 2013-03-31 11:35  lexus  阅读(272)  评论(0编辑  收藏  举报