Differences From Artifact [cad757af38]:
- File src/tcpsocket.c — part of check-in [f1c55cc298] at 2012-09-30 01:10:59 on branch trunk — Make glibc happy. (user: js, size: 3492) [annotate] [blame] [check-ins using]
To Artifact [ba08fae5df]:
- File
src/tcpsocket.c
— part of check-in
[6893b9f5ab]
at
2012-09-30 01:34:46
on branch trunk
— Rename eof to at_end.
This is more fitting as end of file is not really true for a socket. (user: js, size: 3513) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
38 39 40 41 42 43 44 | #include "stream.h" #include "tcpsocket.h" struct CFWTCPSocket { CFWStream stream; int fd; | | | | | | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #include "stream.h" #include "tcpsocket.h" struct CFWTCPSocket { CFWStream stream; int fd; bool at_end; }; static ssize_t sock_read(void *ptr, void *buf, size_t len) { CFWTCPSocket *sock = ptr; ssize_t ret; if ((ret = recv(sock->fd, buf, len, 0)) == 0) sock->at_end = true; return ret; } static bool sock_write(void *ptr, const void *buf, size_t len) { CFWTCPSocket *sock = ptr; ssize_t ret; if ((ret = send(sock->fd, buf, len, 0)) < len) return false; return true; } static bool sock_at_end(void *ptr) { CFWTCPSocket *sock = ptr; return sock->at_end; } static void sock_close(void *ptr) { CFWTCPSocket *sock = ptr; if (sock->fd != -1) close(sock->fd); } static struct cfw_stream_ops stream_ops = { .read = sock_read, .write = sock_write, .at_end = sock_at_end, .close = sock_close }; static bool ctor(void *ptr, va_list args) { CFWTCPSocket *sock = ptr; cfw_stream->ctor(ptr, args); sock->fd = -1; sock->stream.ops = &stream_ops; sock->at_end = false; return true; } static void dtor(void *ptr) { |
︙ | ︙ |