当前位置: 技术问答>linux和unix
linux socket recv Resource temporarily unavailable
来源: 互联网 发布时间:2016-02-27
本文导语: 代码如下: if((socket_fd=socket(AF_INET,SOCK_STREAM,0))==-1){ perror("error socket"); exit(1); } setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out)); setsockopt(socket_fd, SOL_SOCKET, SO_SNDTIMEO, &tv_out, siz...
代码如下:
if((socket_fd=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("error socket");
exit(1);
}
setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out));
setsockopt(socket_fd, SOL_SOCKET, SO_SNDTIMEO, &tv_out, sizeof(tv_out));
op_addr.sin_family = AF_INET;
op_addr.sin_port = htons(atoi(port));
op_addr.sin_addr.s_addr = inet_addr(ip);
bzero(&(op_addr.sin_zero), 8);
if(connect(socket_fd, (struct sockaddr *)&op_addr, sizeof(struct sockaddr)) == -1)
{
perror(" hlrscan connect");
userlog(" hlrscan connect");
strcpy(send_buf, "接口失败");
close(socket_fd);
sleep(3);
return -1;
}
printf("len=%dn",strlen(send1));
printf("send=%sn",send1);
if((send(socket_fd, send1, strlen(send1), 0)) == -1)
{
perror(" error send");
userlog(" hlrscan send");
strcpy(send_buf, "接口失败");
close(socket_fd);
return -1;
}
if((recv(socket_fd,(void *)(recv_buff),sizeof(recv_buff),0))
if((socket_fd=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("error socket");
exit(1);
}
setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out));
setsockopt(socket_fd, SOL_SOCKET, SO_SNDTIMEO, &tv_out, sizeof(tv_out));
op_addr.sin_family = AF_INET;
op_addr.sin_port = htons(atoi(port));
op_addr.sin_addr.s_addr = inet_addr(ip);
bzero(&(op_addr.sin_zero), 8);
if(connect(socket_fd, (struct sockaddr *)&op_addr, sizeof(struct sockaddr)) == -1)
{
perror(" hlrscan connect");
userlog(" hlrscan connect");
strcpy(send_buf, "接口失败");
close(socket_fd);
sleep(3);
return -1;
}
printf("len=%dn",strlen(send1));
printf("send=%sn",send1);
if((send(socket_fd, send1, strlen(send1), 0)) == -1)
{
perror(" error send");
userlog(" hlrscan send");
strcpy(send_buf, "接口失败");
close(socket_fd);
return -1;
}
if((recv(socket_fd,(void *)(recv_buff),sizeof(recv_buff),0))