From: Sam S. <sd...@gn...> - 2003-10-01 15:38:53
|
> * Don Cohen <qba...@vf...3-vap.pbz> [2003-09-30 18:43:05 -0700]: > > Sam Steingold writes: > > > (How does errno work for multiple threads, > > #define errno *thread_specific_errno_address() > > As you see from the previous message I have yet to actually test this > stuff but my current implementation (hack?) is to just rely on errno. > Is this code correct? How would you rather see it done? > Can I do > #define myerrno *thread_specific_errno_address() > And if so, where should I put it? no, the system header that defines errno (be it errno.h or stdlib.h) will define it correctly for your platform. e.g., modules/bindings/glibc/linux.lisp has a lot of problems making errno available because of that. the flip side is that in C you do not have to worry about errno. > Of course, the really ugly part of this solution is that you have to > worry about what other code you execute between this and the later > check. At the moment I think it's ok: > > buffered_nextbyte > > result = BufferedStreamLow_fill(stream)(stream,no_hang); > if (errno == EAGAIN){ > printf("buffered_nextbyte returning -1\n"); // > return -1; /* hang case */ > } this looks kind of yuky. maybe BufferedStreamLow_fill could return -1 instead of relying on errno? Bruno? > local uintL low_fill_buffered_handle (object stream, bool no_hang) { > var sintL result = 0; > var Handle handle = TheHandle(BufferedStream_channel(stream)); > if (!no_hang || ls_avail_p(listen_handle(handle,false,NULL))) { > begin_system_call(); > result = read_helper(handle,BufferedStream_buffer_address(stream,0), > strm_buffered_bufflen,no_hang); > end_system_call(); > if (result<0) # error occurred? > OS_filestream_error(stream); > } > return result; > } > > local uintL low_fill_buffered_socket (object stream, bool no_hang) { > var sintL result; > /* *** doesn't use no_hang? */ > SYSCALL(result,sock_read(TheSocket(BufferedStream_channel(stream)), > BufferedStream_buffer_address(stream,0), > strm_buffered_bufflen)); > return result; > } -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.honestreporting.com> If I had known that it was harmless, I would have killed it myself. |