java socket recv_在socket编程中的recv中“资源暂时不可用”

我想通过套接字编程读取和写入Wanpipe驱动程序(Sangoma卡的网络设备驱动程序),但是我收到此消息错误:“资源暂时不可用” . 该卡正在工作,我看到它在ifconfig中发送和接收数据包 . 我已经包含了我的代码,如果有人帮助我,我会非常高兴 . 一个相关的问题:我将套接字设置为阻塞模式,但recv消息没有阻塞?我怎么能阻止recv?

int main(void)

{

int sd;

int buflen=WP_HEADER + MAX_PACKET;

char buf[buflen];

struct wan_sockaddr_ll sa;

sd = socket(AF_WANPIPE, SOCK_RAW,0);

if (sd < 0) /* if socket failed to initialize, exit */

{

perror("Error Creating Socket");

exit(1);

}

printf("Socket Descriptor:%d\n",sd);

memset(&sa,0,sizeof(struct wan_sockaddr_ll));

strncpy((char*)sa.sll_card,"wanpipe1",sizeof(sa.sl l_card));

strncpy((char*)sa.sll_device,"w1g1",sizeof(sa.sll_ device));

sa.sll_protocol = htons(PVC_PROT);

sa.sll_family = AF_WANPIPE;

if(bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0)

{

perror("error bind failed");

close(sd);

exit(1);

}

int data=0;

int ret=ioctl(sd,FIONBIO,&data);

if (ret < 0)

{

perror("ioctl error!");

close(sd);

return 1;

}

fd_set read_fds;

struct timeval timeout;

timeout.tv_sec = 10;

timeout.tv_usec = 0;

FD_ZERO(&read_fds);

FD_SET(sd,&read_fds);

if(select(sd+1, &read_fds, NULL, NULL, &timeout) < 0)

{

perror("select() error!");

exit(1);

}

if (FD_ISSET(sd,&read_fds))

printf("There is data for reading\n");

else

printf("There is no data for reading\n");*/

// MSG_WAITALL | MSG_PEEK | MSG_OOB

int r=recv(sd,buf,buflen,0);

if (r < 0)

{

perror("Wanpipe raw socket reading");

close(sd);

exit(1);

}

printf("\nNumber of bytes read into the buffer: %d",r);

printf("\nThe read buffer: ");

puts(buf);

close(sd);

}

先感谢您 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值