lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] Moving Layer4+ protocols to main git


From: Sylvain Rochet
Subject: Re: [lwip-devel] Moving Layer4+ protocols to main git
Date: Thu, 10 Sep 2015 14:09:48 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Wed, Sep 09, 2015 at 11:59:46PM +0200, Jan Breuer wrote:
> 2015-09-09 22:52 GMT+02:00 address@hidden <address@hidden>:
> 
> > Jan Breuer wrote:
> >
> >> In full blown OS, you can wait also on other sources - timers, external
> >> events. In netconn API, it is easy to implement this, but in socket API?
> >>
> >
> > Really? How does that work on winsock(2) using "select()"?
> 
> There is the same problem - bare select() can't do it but there is
> alternative API for this
> 
> /* Create Event handle */
> HANDLE sock_ev = WSACreateEvent();
> 
> /* Assign socket to this handle by  */
> WSAEventSelect(sock_fd,sock_ev, FD_READ);
> 
> /* Wait events */
> WSAEVENT pEvents[n];
> pEvents[0] = sock_ev;
> pEvents[1] = other_event;
> res = WaitForMultipleObjects(n, pEvents, FALSE, INFINITE);

For external events, at least on POSIX-system, a pipe can be used to 
wake up a thread spinning on select():

int wakeup_pipe[2];

int main() {
        /* ... */
        pipe(wakeup_pipe);
        /* ... */
        while (1) {
                /* ... */
                FD_SET(wakeup_pipe[0], &readfs);
                /* ... */
                select(...);
        }
        /* ... */
}

void *thread_func() {
        write(wakeup_pipe[1], "", 1);
}

For timers, the usual way is to set the select() timeout just after the 
expiration date of the next due timer:

        while (1) {
                select(..., timeoutleft());  /* sleep up to next timer */
                calltimeout(); /* call any timers which are now due */
        }

Sylvain

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]