On Sun, Jan 13, 2013 at 3:03 PM, Vic Sage <vic.s...@icloud.com> wrote: > I'm writing a multiplexed TCP-based server that reads "\n"-terminated strings > from clients and does something with them. Since this is one process with > multiple client connections, it uses select() (or, actually, can_read from > IO::Select) to block until data has arrived from any client. > > It's my understanding that TCP does not preserve "message boundaries." That > is, if a client writes: > > $sock->autoflush(1); > print $sock "abel\n"; > print $sock "baker\n"; > print $sock "charlie\n"; > > ... there are no guarantees about what will be returned from the server's > system buffer by sysread() when select() pops. It could be "a", or "abel\n", > or "abel\nbak", etc. > > What I *want* is to block until an entire "\n"-terminated string [can that be > referred to as a "line"?] can be retrieved from one of my clients. I'm sure > I could work out the logic to maintain application-level buffers, but I > suspect I would merely be reinventing the wheel, one bug at a time :-). > What does the experienced Perl programmer - or socket-level programmer in > general - do in this situation? >
I'm not experienced in heavy duty socket-level programming but you may want to invest in learning POE: https://poe.perl.org It's already refined many of the wheels you'll need and appears well documented. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/