On 10 Feb 2003, Florin Malita wrote:
> TIP: Se poate face blocking read cu timeout - bagi un select inainte de
> read:
>
> ssize_t read_tout(int fd, void *buf, size_t count, int tout_sec){
> fd_set rd_set;
> struct timeval tv;
> int res;
>
> FD_ZERO(&rd_set);
> FD_SET(fd, &rd_set);
>
> tv.tv_sec = tout_sec;
> tv.tv_usec = 0;
>
> /* blocking cel mult tout_sec */
> if((res = select(fd + 1, &rd_set, NULL, NULL, &tv)) <= 0){
> /* error or timeout */
> return res;
> }
>
Dar nu avem aici a race condition ?
Teoretic intre select si read se poate intampla ceva ca read-ul sa se
blocheze. So O_NONBLOCK ramane de baza (chiar daca faci select() inainte)
> /* acum read nu mai e blocking */
> return read(sock, buf, count);
> }
>
>
> spor
>
> --
> Florin Malita web: http://www.malinux.net
> public key: http://www.malinux.net/data/fmalita.gpg
>
> -- Attached file included as plaintext by Listar --
> -- File: signature.asc
> -- Desc: This is a digitally signed message part
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
>
> iD8DBQA+R9q09npXhj/Ohf8RAkvqAJ4mOIy8IFP0mQxiFcxwTxmNBjccbwCgnQk2
> Vlk0sBGAhfJSDSTr5HtvTOU=
> =jSo/
> -----END PGP SIGNATURE-----
>
>
> --
> Pentru dezabonare, trimiteti mail la
> [EMAIL PROTECTED] cu subiectul 'unsubscribe rlug'.
> REGULI, arhive si alte informatii: http://www.lug.ro/mlist/
>
>
>
----------------------------
Mihai RUSU
Disclaimer: Any views or opinions presented within this e-mail are solely
those of the author and do not necessarily represent those of any company,
unless otherwise specifically stated.
--
Pentru dezabonare, trimiteti mail la
[EMAIL PROTECTED] cu subiectul 'unsubscribe rlug'.
REGULI, arhive si alte informatii: http://www.lug.ro/mlist/