recvfrom with timeout @ 071's blog :: 隨意窩 Xuite日誌
    1. 沒有新回應!
  • 201805241500recvfrom with timeout

    int recvfrom_withtimeout(int fd, char *buf, size_t buf_n,unsigned int flags,struct sockaddr* addr,socklen_t *len,unsigned int sec=10,unsigned usec=0)
    {
    struct timeval tv;
    fd_set readfds;
    int n=0;

    FD_ZERO(&readfds);
    FD_SET(fd,&readfds);
    tv.tv_sec=sec;
    tv.tv_usec=usec;
    select(fd+1,&readfds,NULL,NULL,&tv);
    if(FD_ISSET(fd,&readfds))
    {
    n=recvfrom(fd,buf,buf_n,flags,addr,len);
    return n;
    } else {
    return 0;
    }

    return -1;
    }

    mpi4py Python (...|日誌首頁|python pigame 貪食蛇上一篇mpi4py Python (environment setup)...下一篇python pigame 貪食蛇
    回應