Commit c940a9f8 authored by jan.koester's avatar jan.koester
Browse files

timeout method for posix systems

parent adb56331
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -70,3 +70,32 @@ void netplus::socket::setnonblocking(){
        throw exception;
    }
}

void netplus::socket::setTimeout(int usec){
    struct timeval timeout;
    timeout.tv_sec =  0;
    timeout.tv_usec = usec;
    if (setsockopt (_Socket, SOL_SOCKET, SO_RCVTIMEO, &timeout,
        sizeof timeout) < 0){

        char errstr[512];
        strerror_r_netplus(errno,errstr,512);

        NetException exception;
        exception[NetException::Error] << "Could not set ClientSocket Recv timeout"<< errstr;
        throw exception;
    }


    if (setsockopt (_Socket, SOL_SOCKET, SO_SNDTIMEO, &timeout,
        sizeof timeout) < 0){

        char errstr[512];
        strerror_r_netplus(errno,errstr,512);

        NetException exception;
        exception[NetException::Error] << "Could not set ClientSocket Send timeout" << errstr;
        throw exception;

    }
}
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ namespace netplus {
            socket();
            virtual      ~socket();
            void                     setnonblocking();
            
            void                     setTimeout(int usec);
            
            virtual void             accept(socket *csock)=0;
            virtual void             bind()=0;
+4 −0
Original line number Diff line number Diff line
@@ -80,3 +80,7 @@ void netplus::socket::setnonblocking(){
    }
}

void netplus::socket::setTimeout(int usec){
    return;
}