From: Wai-Sun Chia Date: 2001-07-10T16:09:15+09:00 Subject: [ruby-talk:17595] Re: low-level TCP/IP manipulations? Al Chou wrote: > Hi, all, > > This question may be naive or just plain stupid, but searching the list archive > for "TCP" and "IP" didn't turn up anything that looked relevant, so here goes. > > I'm testing some network hardware and software and (think I) need to be able to > manipulate TCP and/or IP at kind of a low level. For instance, one of my test > cases includes the requirement "device should return a TCP/IP No Listener error > code". I'm writing an emulator for this device in Ruby and wondering whether I > can get such fine-grained control over network communications from within Ruby. > What you want is ECONNREFUSED (see connect(2)) return code, which unfortunately is not returned in Ruby/Socket. socket.c 754 if (status < 0) { 755 switch (errno) { 756 case EAGAIN: 757 #ifdef EINPROGRESS 758 case EINPROGRESS: 759 #endif 760 thread_write_select(fd); 761 continue; 762 763 #ifdef EISCONN 764 case EISCONN: 765 status = 0; 766 errno = 0; 767 break; 768 #endif 769 } 770 } What you can do is just add additional case statements for the switch construct and you're off, f'rinstance: switch (errno) { case EAGAIN: : case ECONNREFUSED: break; case EBADF: break; etc. etc. Recompile Ruby and test... Let us know. -- Wai-Sun "Squidster" Chia Unix/Web Developer/RHCE Professional Services