Yippie, after one week, and loud thinking while writing on perl monks I finally found the problem.
In the event_loop a select() iterates over two arrays/IO::Select objects ($rd_handles, $wt_handles).
After server start $rd_handles contains only the "$main_socket" and the parent selects only for that socket. After forking, the sockets are closed (child socket in parent, main_socket in child)
BUT the $main_socket remained in $rd_handles of the child process. This caused the EBADF, since there was a closed fdesc in that array. It was always there, I dont understand why one variant worked when the other didn't. Strangely enough, the first step to correct that, $rd_handles->remove($main_socket) didn't work. The $main_socket was still in the array along with valid sockets and I still got EBADF from select().
So I decided to undef $rd_handles/$wt_handles, recreate the two objects and add the child socket there.
That fixed it. Thanks for your input, sometimes I have to think loud and none of my coworkers is suitable for that.
As for the architecture... it is a combination of accept once / select over a set of sockets added to rd_/wt_handles after accept and callback procedures registered for each of these sockets. Now when a message arrives over a socket, the associated procedure is called and the result is send back to the client.
It took me a while to understand the inner workings of Msg.pm (props to Mr. Sriram Srinivasan). The module wasn't designed with a forking solution in mind and in it's original form is not intended for production use (as stated by the author). For a long time I avoided messing with it, but now I had to. Learned a lot while doing so.
Best regards
gnork
cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
errors->(c)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.