--- "Ralf S. Engelschall" <[EMAIL PROTECTED]> wrote: > On Fri, Jul 11, 2003, Damon Hastings wrote: > > > This is probably a stupid question, but how do you do line-oriented > blocking > > socket reads in Pth? There's a pth_read() which I assume blocks until a > > specified number of bytes (or eof) are received -- but I'm looking for > > something like pth_gets() to block until a newline is received. I don't > > think you could even write a simple webserver in Pth without such a > > function, though you could of course implement it yourself via a > > non-blocking pth_read in a loop. I'll implement it myself if need be, > > though I would rather trust someone else's code, as I've never used Pth > > before and there are lots of tricky error conditions in socket > programming. > > > > The documentation at http://www.gnu.org/software/pth/pth-manual.html > > includes a simple output-only server as a code example -- is there an > > input/output example somewhere? > > See the file test_common.c in the Pth source tree. It provides a > pth_readline() function (just a small but sufficient buffered wrapper > around pth_read()) which should do exactly what you want.
It looks like pth_readline_ev() reads a fixed number of bytes at a time (i.e. 1024) and will block until it reads that many (or eof). Is that right? That works great for reading a file, where more bytes (or eof) are always available, but I'm reading from a socket. I was considering a non-blocking approach like: pth_fdmode(fd, PTH_FDMODE_NONBLOCK); while (newline not read yet) { pth_select on fd readable, with long timeout; bytes = pth_read(fd, buff, 1024); if (bytes == 0) cleanup on closed connection } Is there a more efficient approach than this? And should I put a sleep in that loop, or will the scheduler automatically handle everything? (I'll have about 150 threads in this loop simultaneously, each reading from its own socket, with each socket delivering about 1 line of input per second.) By the way, thanks for the excellent package -- I don't think I could have 150 threads running without it! :-) Damon __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com ______________________________________________________________________ GNU Portable Threads (Pth) http://www.gnu.org/software/pth/ Development Site http://www.ossp.org/pkg/lib/pth/ Distribution Files ftp://ftp.gnu.org/gnu/pth/ Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/ User Support Mailing List [EMAIL PROTECTED] Automated List Manager (Majordomo) [EMAIL PROTECTED]