Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^5: Socket descriptor passed across fork -- hangingby Marshall (Canon) |
on Oct 15, 2011 at 17:26 UTC ( [id://931679]=note: print w/replies, xml ) | Need Help?? |
What are the tradeoffs of using sysread/syswrite vs. read/print? The obvious one is I have to implement my own line-oriented read for the first line of the protocol, which I have to read and parse. Is dropping down a level going to be of significant benefit, and if so in what? This is a good question. Perhaps some other Monks will chime in here.. If you read my code and can see where it can go..Implementing a line oriented protocol is not hard. You have a non-standard "\n" termination of the line but you just check the last character for "\n" to see if the line is finished. $buf is a string, not an array, so you can use a substr() operation, or just run a regex on the $buf chars to see if the last char is "\n"; The big difference between sysread and read is non-buffered vs buffered. This might lead to lower performance when many lines are being sent at once. Depends upon how smart the readn() is. However, it sounds to me like you just need to implement a server that talks with some clients over which you have no control. And if the performance is adequate and if your server's reliability is rock solid, I would "stick a fork in it" and say its done! Normally for something like this: reliability is the main thing...Doesn't crash..doesn't loose data..recovers when a client crashes..function is 100% great in all respects. I see ways to make this faster, but if that is not necessary, then you are loosing the argument. Kick ass with less than one page of Perl code and go!
In Section
Seekers of Perl Wisdom
|
|