× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Socket people,

I am getting an intermitent "socket in use" error in my as400 socket server
pgm as I test my win95 to as400 socket code.

Even though the shutdown( ) and close( ) functions run without error, the
next time I run my pgm, a "socket in use" error occurs on the Bind( ) stmt.
And NetStat shows my prev use of the socket still in a listen state on the
socket.

By using SetSockOpt( ), I think I have solved the problem. But varying the
use of shutdown( ) and close( ) also reduced the frequency of the in use
condition.

My question: Why does the correct use of shutdown( ) and close( ) not always
free the socket?

Is there some timeout value that can be set?

Also, is there an api equivalent of NetStat?  When my pgm gets an "in use"
return code, can it find out what job is using the socket?

And,  Can my pgm forcefully free up a socket that it knows is not really in
use?


Thanks,

Steve Richter


Here are the variations of the code of the server pgm:


This code gets the most "in use" errors. ( more than half the time )
 C                   Eval      SD = Socket (AF_INET: SOCK_STREAM: 0 )

 C                   Eval      SocketAddr = *ALLX'00'
 C                   Eval      SinFamily  = AF_INET
 C                   Eval      SinPort    = 3005
 C                   Eval      SinAddr    = INADDR_ANY
 C                   Eval      rc = Bind (SD: %ADDR(SocketAddr) :
%SIZE(SocketAddr))

 C                   Eval      rc = Listen (SD: 1)

 c                   Eval      SD2 = Accept( SD: %Addr(AccpAddr):
%Addr(AccpAddrLgth) )

 C                   Eval      Lx = Recv( SD2: %Addr(SocketData) :
%Size(SocketData) : 0 )

 c                   Eval      Rc = SysShutdown( SD: 2 )

c                   Eval      Rc = SysShutdown( SD2: 2 )

 c                   Eval      Rc = Close( SD )

c                   Eval      Rc = Close( SD2 )


By shutting down the Listen socket (SD) immed after the Accept( ), the inuse
error occurs maybe 20 pct of the time.  ( also by running shutdown(sd),
close(sd), shutdown(sd2), close(sd2) )
 C                   Eval      SD = Socket (AF_INET: SOCK_STREAM: 0 )

 C                   Eval      rc = Bind (SD: %ADDR(SocketAddr) :
%SIZE(SocketAddr))

 C                   Eval      rc = Listen (SD: 1)

 c                   Eval      SD2 = Accept( SD: %Addr(AccpAddr):
%Addr(AccpAddrLgth) )


 c                   Eval      Rc = SysShutdown( SD: 2 )

 c                   Eval      Rc = Close( SD )

 C                   Eval      Lx = Recv( SD2: %Addr(SocketData) :
%Size(SocketData) : 0 )

c                   Eval      Rc = SysShutdown( SD2: 2 )

c                   Eval      Rc = Close( SD2 )



Best results are had by running SetSockOpt( ) to make the socket reusable.
 C                   Eval      SD = Socket (AF_INET: SOCK_STREAM: 0 )

 c                   Eval      rc = SetSockOpt( SD : SOL_SOCKET :
SO_REUSEADDR :
 c                                              %Addr(OptVal) :
%Size(OptVal) )

 C                   Eval      rc = Bind (SD: %ADDR(SocketAddr) :
%SIZE(SocketAddr))

 C                   Eval      rc = Listen (SD: 1)

 c                   Eval      SD2 = Accept( SD: %Addr(AccpAddr):
%Addr(AccpAddrLgth) )


 c                   Eval      Rc = SysShutdown( SD: 2 )

 c                   Eval      Rc = Close( SD )

 C                   Eval      Lx = Recv( SD2: %Addr(SocketData) :
%Size(SocketData) : 0 )

c                   Eval      Rc = SysShutdown( SD2: 2 )

c                   Eval      Rc = Close( SD2 )





+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.