Unix Programming - [socket] test if socket descriptor is valid

This is Interesting: Free IT 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, 7:35 am

Hi

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

maybe fstat ?

Mark Holland

2007-09-27, 1:34 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






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com