ioctl() on socket fd's take 3 seconds on 1.7.7

Jason Curl jcurlnews@arcor.de
Tue Nov 9 08:20:00 GMT 2010


Hello,

Cygwin 1.7.7 is definitely an improvement over 1.5.x but I see a
regression on 1.7.7 (on Win7 x64) that ioctl() on a socket FD takes 3 
seconds.

I'm writing my own ifconfig replacement and I do the following:

     #define IFC_BUF     10 * sizeof(struct ifreq)
     #define MAX_IFC_BUF 8192

     buf = malloc(IFC_BUF);
     buflen = IFC_BUF;
     s = socket(AF_INET, SOCK_DGRAM, 0);
     ifc.ifc_buf = buf;
     intf = FALSE;
     while (buflen < MAX_IFC_BUF && !intf) {
         ifc.ifc_len = buflen;
         if (ioctl(s, SIOCGIFCONF, &ifc) >= 0) {
             ^^^^^
The ioctl() takes 3 seconds to execute. I've tested cygwin1.dll 1.7.7-1 
and snapshot 20101102.

Not only this ioctl, but also the following ioctl()'s take 3 seconds per
call:
     if (ioctl(s, SIOCGIFADDR, intf[h].ifr) < 0) {
     if (ioctl(s, SIOCGIFNETMASK, intf[h].ifr) < 0) {
     if (ioctl(s, SIOCGIFBRDADDR, intf[h].ifr) < 0) {
     if (ioctl(s, SIOCGIFDSTADDR, intf[h].ifr) < 0) {
     if (ioctl(s, SIOCGIFHWADDR, intf[h].ifr) < 0) {
     if (ioctl(s, SIOCGIFFLAGS, intf[h].ifr) < 0) {

When running 'strace' on my executable, execution is fast (there are no
longer the 3 second timeouts) and the program takes 200ms to complete,
not 1.5 minutes (for 8 nics). However, the following is visible in the
logs (I used cygwin1-20101102.dll for the latest tests). Notice the 
exception:

   166   32185 [main] ipcheck 5580 cygwin_socket: socket (2, 2 (flags 
0x0), 0)
29950   62135 [main] ipcheck 5580 wsock_init: res 0
    30   62165 [main] ipcheck 5580 wsock_init: wVersion 514
    22   62187 [main] ipcheck 5580 wsock_init: wHighVersion 514
    19   62206 [main] ipcheck 5580 wsock_init: szDescription WinSock 2.0
    20   62226 [main] ipcheck 5580 wsock_init: szSystemStatus Running
    19   62245 [main] ipcheck 5580 wsock_init: iMaxSockets 0
    18   62263 [main] ipcheck 5580 wsock_init: iMaxUdpDg 0
    21   62284 [main] ipcheck 5580 wsock_init: lpVendorInfo 0
  2807   65091 [main] ipcheck 5580 build_fh_pc: fh 0x61242014
    74   65165 [main] ipcheck 5580 fhandler_base::set_flags: flags 
0x10002, supplied_bin 0x0
    23   65188 [main] ipcheck 5580 fhandler_base::set_flags: 
O_TEXT/O_BINARY set in flags 0x10000
    21   65209 [main] ipcheck 5580 fhandler_base::set_flags: filemode 
set to binary
    19   65228 [main] ipcheck 5580 fdsock: fd 3, name '', soc 0x170
    24   65252 [main] ipcheck 5580 cygwin_socket: 3 = socket (2, 2 
(flags 0x0), 0)
   166   65418 [main] ipcheck 5580 ioctl: fd 3, cmd 80087364
--- Process 5580, exception C0000005 at 610C8C86
38639  104057 [main] ipcheck 5580 exception::handle: In 
cygwin_except_handler exc 0xC0000005 at 0x610C8C86 sp 0x26C7A0
   114  104171 [main] ipcheck 5580 exception::handle: In 
cygwin_except_handler sig 11 at 0x610C8C86
    31  104202 [main] ipcheck 5580 exception::handle: In 
cygwin_except_handler calling 0x0
    31  104233 [main] ipcheck 5580 __set_errno: void san::leave():284 val 14
    26  104259 [main] ipcheck 5580 fhandler_socket::ioctl: error in 
get_ifconf
    28  104287 [main] ipcheck 5580 fhandler_socket::ioctl: -1 = 
ioctl_socket (80087364, CDAD80)
    23  104310 [main] ipcheck 5580 ioctl: returning -1

Interestingly enough, the program works. That is, it finds all 
interfaces and returns correct values (except interface names are UUIDs 
instead of something more friendly like "eth0" that existed in 1.5.26).

My antivirus has been closed (not simply deactivated) with no change in 
behaviour.

It will be a little later when I'm able to generate a working test case.

Thanks & Best Regards,
Jason.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list