Re: Sockets and threads...



Mark Seger <Mark.Seger@xxxxxx> wrote:
I want to open some sockets in one thread and write to them from my main
process and think this is very doable.

Open a socket to what? Are you opening sockets "internally" from one
thread to another within the same process? Is the "open" doing the accept,
or the connect?

I've been looking around a lot
for answers to this and I think I've figure it out but would like to
hear if my thinking is indeed correct:

Sockets are global to the process/threads already and so you don't have
to pass around file descriptors to make them visible to the main
process. I had tried (and failed) to share descriptors and failed
because they're not simple variables.

Can you show code to illustrate this problem?

Looking at some code snippets it feels like all I need to do is get the
file number from $descriptor->fileno() and share that.

One way to convert a file number, assuming it's in $fn back to a
descriptor is the following:

open ($fd, ">&$fn);

That only works if you only need to write on the socket. I can't
figure out how to open if you need both read and write.

and now I can syswrite() to it back in my main code. At least it seems
to be working correctly. Is this indeed the 'preferred' way to do this?
Am I missing something? Is there a better way?

In most cases I can dream up in which I might want to use this, I suspect
I'd prefer to arrange the code differently in the first place.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • [patch] SOCK_CLOEXEC, SOCK_NONBLOCK and MSG_CMSG_CLOEXEC
    ... MSG_CMSG_CLOEXEC to recvmsgmakes file descriptors ... I do not pass the SOCK_* flags to MAC because this may cause incorrect ... +.Xr socket 2, ...
    (freebsd-hackers)
  • Re: reading a fixed-length message
    ... properly (close the socket, serial port, etc.) ... depending on the descriptors you are using. ... if serialfd for write ...
    (comp.unix.programmer)
  • are socket handles always usabele by file i/o functions?
    ... descriptors are IFS handles by using these descriptors ... I thought that if I create socket from WSAPROTOCOL_INFO which has not ... But it's written that if SPI does not create IFS handle, ... can read that it returns handle that can be used in file I/O functions. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Linux select command issues
    ... double-check any descriptors (by referring ... It comes down to whether or not 'select' is a pure status reporting ... If it's a pure status reporting function, ... What would happen if you 'select'ed for write on a socket that wasn't ...
    (comp.unix.programmer)