Permalink
Browse files

Make io_read and io_write return EAGAIN again, fix writev typo

  • Loading branch information...
1 parent d65f89e commit 9c20a703387d465babad8147c86a105604dbbb46 Scott Bronson committed Apr 6, 2007
Showing with 18 additions and 27 deletions.
  1. +2 −1 CHANGES
  2. +15 −25 atom.c
  3. +1 −1 poller.h
View
@@ -1,5 +1,5 @@
TODO
-- Added mock hooks for readv and writev but they're definitely not debugged.
+- Added mock hooks for readv and writev but they're definitely not debugged. Shake them out.
- Rename socket_addr to socket_address.
- Split the static mock events into a mocker api and a static mocker. That allows us to read mock events from files later.
Mostly it allows us to isolate the awful hacks in the current code behind a clean API.
@@ -23,6 +23,7 @@ TODO
- Returning EPIPE for 0-length reads is pretty stupid. But we have to return SOME error. Is there a better alternative?
DONE:
+* io_read and io_write return EAGAIN again. Now you should never see err==0 && len==0.
* Try to standardize return codes: every one returns an error code or 0 on no error.
(except for io_wait, which still returns the # of events that need to be dispatched).
* Added io_close. This allows mock fds to close without closing, say, stdout.
View
40 atom.c
@@ -56,12 +56,9 @@ int io_atom_read(struct io_poller *poller, io_atom *io, char *buf, size_t cnt, s
return EPIPE;
}
- // an error ocurred during the read
- if(errno == EAGAIN || errno == EWOULDBLOCK) {
- // turns out there was nothing to read after all? weird.
- // there was no error, but nothing to process either.
- return 0;
- }
+#if EAGAIN != EWOULDBLOCK
+ if(errno == EWOULDBLOCK) errno = EAGAIN;
+#endif
return errno ? errno : -1;
}
@@ -87,12 +84,9 @@ int io_atom_readv(struct io_poller *poller, io_atom *io, const struct iovec *vec
return EPIPE;
}
- // an error ocurred during the read
- if(errno == EAGAIN || errno == EWOULDBLOCK) {
- // turns out there was nothing to read after all? weird.
- // there was no error, but nothing to process either.
- return 0;
- }
+#if EAGAIN != EWOULDBLOCK
+ if(errno == EWOULDBLOCK) errno = EAGAIN;
+#endif
return errno ? errno : -1;
}
@@ -129,18 +123,16 @@ int io_atom_write(struct io_poller *poller, io_atom *io, const char *buf, size_t
if(len > 0) {
*wrlen = len;
return 0;
- }
+ }
if(len < 0) {
- /*
- if(errno == ECONNRESET) {
- return EPIPE;
- }
- */
+#if EAGAIN != EWOULDBLOCK
+ if(errno == EWOULDBLOCK) errno = EAGAIN;
+#endif
return errno ? errno : -1;
}
- // nothing was written but there was no error??
+ // nothing was written but there was no error?! This is an OS error right?
return 0;
}
@@ -160,15 +152,13 @@ int io_atom_writev(struct io_poller *poller, io_atom *io, const struct iovec *ve
}
if(len < 0) {
- /*
- if(errno == ECONNRESET) {
- return EPIPE;
- }
- */
+#if EAGAIN != EWOULDBLOCK
+ if(errno == EWOULDBLOCK) errno = EAGAIN;
+#endif
return errno ? errno : -1;
}
- // nothing was written but there was no error??
+ // nothing was written but there was no error?!
return 0;
}
View
@@ -127,7 +127,7 @@ int io_poller_init(io_poller *poller, io_poller_type type);
#define io_read(a,io,buf,cnt,rdlen) (*(a)->funcs.read)(a,io,buf,cnt,rdlen)
#define io_readv(a,io,vec,rdlen) (*(a)->funcs.read)(a,io,vec,rdlen)
#define io_write(a,io,buf,cnt,wrlen) (*(a)->funcs.write)(a,io,buf,cnt,wrlen)
-#define io_writev(a,io,vec,cnt,wrlen) (*(a)->funcs.write)(a,io,vec,cnt,wrlen)
+#define io_writev(a,io,vec,cnt,wrlen) (*(a)->funcs.writev)(a,io,vec,cnt,wrlen)
#define io_connect(a,io,rp,wp,ra,f) (*(a)->funcs.connect)(a,io,rp,wp,ra,f)
#define io_accept(a,io,rp,wp,f,l,r) (*(a)->funcs.accept)(a,io,rp,wp,f,l,r)
#define io_listen(a,io,rp,l) (*(a)->funcs.listen)(a,io,rp,l)

0 comments on commit 9c20a70

Please sign in to comment.