For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2007 > [socket] test if socket descriptor is valid









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [socket] test if socket descriptor is valid
mbm

2007-09-27, 8:07 am

Hi

Is it possible to check that a socket descriptor is valid before
receiveing data ( recv) ?

maybe fstat ?

Mark Holland

2007-09-27, 7:10 pm

"mbm" <mbmessaoud@yahoo.com> wrote in message
news:1190890077.826077.15620@57g2000hsv.googlegroups.com...
> Hi
>
> Is it possible to check that a socket descriptor is valid before
> receiveing data ( recv) ?
>
> maybe fstat ?


Why bother? recv will return EBADF if the descriptor is invalid
anyway. However you are correct - using fstat you can check the
st_mode field for the file type. Note this is only valid if fstat
returns correctly... you may have a completely invalid fd (e.g. you
previously closed this file) in which case fstat will return EBADF
also.

Mark


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com