M
Mark Seger
I want to open some sockets in one thread and write to them from my main
process and think this is very doable. 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.
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);
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?
-mark
process and think this is very doable. 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.
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);
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?
-mark