esr@mrst.UUCP (Eric S. Rose) (07/14/87)
Hello there.... Can anyone help me with a problem involving sockets? I have a simple server/client program where the server could be present on any one of several machines on the Ethernet. If a client does a 'connect' to a machine that does not have the server, an error is returned ('ECONNREFUSED'). This is Ok, I'll try another. The next time I get another error, ('EINVAL') even though this time, it is trying to connect to the machine where the server really is. If I close the socket connection *after* the bad connection, re-open it, and try the connect on the new machine, it works fine. It seems that when connect fails, it changes some internal flags that need to be reset. Is there any way to make this not happen, or reset it? I also tried: setsockopt ( sock, SOL_SOCKET, SO_REUSEADDR, (char *)0, 0); As well as: x = 1; setsockopt ( sock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); after the socket call and before the connect, but there was no difference. We don't have sources, and the documentation is pretty sketchy on these areas. Thanks in advance for any helpful hints.... Eric "Has anyone seen... | Eric Rose a dog dyed dark green?" | MRS Technology, Acton, MA. - B-52's | (617)264-4588 | ...genrad \ | >- !mrst!esr | ...necis /
coltoff@PRC.Unisys.COM (Joel Coltoff) (08/10/88)
I've got an application that uses a server to spawn a child. For testing purposes I have a tty attached to the child as well. My server does an execl( "/usr/bin/cmdtool", "cmdtool", "/usr/acct/coltoff/bin/conf", 0 ); This way I can enter debugging commands and display error messages. From another window I send data down the socket to the child. I am running into problems when /usr/acct/coltoff/bin/conf tries to find the descriptor to use as the socket. I know for a fact that in the server it's fileno is 3. Since I was real careful to close() all unneeded files I figured what I could do in the child was do a stat() on all descriptors until I got back a -1 or found one that had the S_IFSOCK bit set. The closest I get is S_IFIFO. I seems to work so I forged blindly ahead putting off the inevitable search for an answer until later. That happened sooner than I thought it would. Now I am trying to get this code to work under X11 and want to start an xterm instead of a cmdtool. The descriptor in the child that used to be S_IFIFO is now S_IFREG and this doesn't work at all. With that background here are my questions. How does a child program go about finding out what descriptor is the socket from it's parent? Should the child do a dup() on it right away so that if it does any open() calls the socket isn't clobbered? For the brave among you, why does the program behave one way under X11R2 and another under suntools? Thanks in advance. -- - Joel {psuvax1,sdcrdcf}!burdvax!coltoff (UUCP) coltoff@burdvax.prc.unisys.com (ARPA)