Changeset 740 for vendor/current/lib/async_req
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/lib/async_req
- Files:
-
- 1 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/async_req/async_sock.c
r414 r740 37 37 #endif 38 38 39 struct async_send_state {39 struct sendto_state { 40 40 int fd; 41 41 const void *buf; 42 42 size_t len; 43 43 int flags; 44 const struct sockaddr_storage *addr; 45 socklen_t addr_len; 44 46 ssize_t sent; 45 47 }; 46 48 47 static void async_send_handler(struct tevent_context *ev,49 static void sendto_handler(struct tevent_context *ev, 48 50 struct tevent_fd *fde, 49 51 uint16_t flags, void *private_data); 50 52 51 struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx, 52 struct tevent_context *ev, 53 int fd, const void *buf, size_t len, 54 int flags) 53 struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 54 int fd, const void *buf, size_t len, int flags, 55 const struct sockaddr_storage *addr) 55 56 { 56 57 struct tevent_req *result; 57 struct async_send_state *state;58 struct sendto_state *state; 58 59 struct tevent_fd *fde; 59 60 60 result = tevent_req_create(mem_ctx, &state, struct async_send_state);61 result = tevent_req_create(mem_ctx, &state, struct sendto_state); 61 62 if (result == NULL) { 62 63 return result; … … 66 67 state->len = len; 67 68 state->flags = flags; 68 69 fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, async_send_handler, 69 state->addr = addr; 70 71 switch (addr->ss_family) { 72 case AF_INET: 73 state->addr_len = sizeof(struct sockaddr_in); 74 break; 75 #if defined(HAVE_IPV6) 76 case AF_INET6: 77 state->addr_len = sizeof(struct sockaddr_in6); 78 break; 79 #endif 80 case AF_UNIX: 81 state->addr_len = sizeof(struct sockaddr_un); 82 break; 83 default: 84 state->addr_len = sizeof(struct sockaddr_storage); 85 break; 86 } 87 88 fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, sendto_handler, 70 89 result); 71 90 if (fde == NULL) { … … 76 95 } 77 96 78 static void async_send_handler(struct tevent_context *ev,97 static void sendto_handler(struct tevent_context *ev, 79 98 struct tevent_fd *fde, 80 99 uint16_t flags, void *private_data) … … 82 101 struct tevent_req *req = talloc_get_type_abort( 83 102 private_data, struct tevent_req); 84 struct async_send_state *state = 85 tevent_req_data(req, struct async_send_state); 86 87 state->sent = send(state->fd, state->buf, state->len, state->flags); 103 struct sendto_state *state = 104 tevent_req_data(req, struct sendto_state); 105 106 state->sent = sendto(state->fd, state->buf, state->len, state->flags, 107 (struct sockaddr *)state->addr, state->addr_len); 88 108 if ((state->sent == -1) && (errno == EINTR)) { 89 109 /* retry */ … … 97 117 } 98 118 99 ssize_t async_send_recv(struct tevent_req *req, int *perrno)100 { 101 struct async_send_state *state =102 tevent_req_data(req, struct async_send_state);119 ssize_t sendto_recv(struct tevent_req *req, int *perrno) 120 { 121 struct sendto_state *state = 122 tevent_req_data(req, struct sendto_state); 103 123 104 124 if (tevent_req_is_unix_error(req, perrno)) { … … 108 128 } 109 129 110 struct async_recv_state {130 struct recvfrom_state { 111 131 int fd; 112 132 void *buf; 113 133 size_t len; 114 134 int flags; 135 struct sockaddr_storage *addr; 136 socklen_t *addr_len; 115 137 ssize_t received; 116 138 }; 117 139 118 static void async_recv_handler(struct tevent_context *ev,140 static void recvfrom_handler(struct tevent_context *ev, 119 141 struct tevent_fd *fde, 120 142 uint16_t flags, void *private_data); 121 143 122 struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx, 123 struct tevent_context *ev, 124 int fd, void *buf, size_t len, int flags) 144 struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx, 145 struct tevent_context *ev, 146 int fd, void *buf, size_t len, int flags, 147 struct sockaddr_storage *addr, 148 socklen_t *addr_len) 125 149 { 126 150 struct tevent_req *result; 127 struct async_recv_state *state;151 struct recvfrom_state *state; 128 152 struct tevent_fd *fde; 129 153 130 result = tevent_req_create(mem_ctx, &state, struct async_recv_state);154 result = tevent_req_create(mem_ctx, &state, struct recvfrom_state); 131 155 if (result == NULL) { 132 156 return result; … … 136 160 state->len = len; 137 161 state->flags = flags; 138 139 fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ, async_recv_handler, 162 state->addr = addr; 163 state->addr_len = addr_len; 164 165 fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ, recvfrom_handler, 140 166 result); 141 167 if (fde == NULL) { … … 146 172 } 147 173 148 static void async_recv_handler(struct tevent_context *ev,174 static void recvfrom_handler(struct tevent_context *ev, 149 175 struct tevent_fd *fde, 150 176 uint16_t flags, void *private_data) … … 152 178 struct tevent_req *req = talloc_get_type_abort( 153 179 private_data, struct tevent_req); 154 struct async_recv_state *state = 155 tevent_req_data(req, struct async_recv_state); 156 157 state->received = recv(state->fd, state->buf, state->len, 158 state->flags); 180 struct recvfrom_state *state = 181 tevent_req_data(req, struct recvfrom_state); 182 183 state->received = recvfrom(state->fd, state->buf, state->len, 184 state->flags, (struct sockaddr *)state->addr, 185 state->addr_len); 159 186 if ((state->received == -1) && (errno == EINTR)) { 160 187 /* retry */ … … 172 199 } 173 200 174 ssize_t async_recv_recv(struct tevent_req *req, int *perrno)175 { 176 struct async_recv_state *state =177 tevent_req_data(req, struct async_recv_state);201 ssize_t recvfrom_recv(struct tevent_req *req, int *perrno) 202 { 203 struct recvfrom_state *state = 204 tevent_req_data(req, struct recvfrom_state); 178 205 179 206 if (tevent_req_is_unix_error(req, perrno)) { … … 359 386 size_t total_size; 360 387 uint16_t flags; 388 bool err_on_readability; 361 389 }; 362 390 … … 386 414 goto fail; 387 415 } 388 state->flags = TEVENT_FD_WRITE; 389 if (err_on_readability) { 390 state->flags |= TEVENT_FD_READ; 391 } 416 state->flags = TEVENT_FD_WRITE|TEVENT_FD_READ; 417 state->err_on_readability = err_on_readability; 392 418 393 419 if (queue == NULL) { … … 435 461 436 462 if ((state->flags & TEVENT_FD_READ) && (flags & TEVENT_FD_READ)) { 437 tevent_req_error(req, EPIPE); 438 return; 463 int ret, value; 464 465 if (state->err_on_readability) { 466 /* Readable and the caller wants an error on read. */ 467 tevent_req_error(req, EPIPE); 468 return; 469 } 470 471 /* Might be an error. Check if there are bytes to read */ 472 ret = ioctl(state->fd, FIONREAD, &value); 473 /* FIXME - should we also check 474 for ret == 0 and value == 0 here ? */ 475 if (ret == -1) { 476 /* There's an error. */ 477 tevent_req_error(req, EPIPE); 478 return; 479 } 480 /* A request for TEVENT_FD_READ will succeed from now and 481 forevermore until the bytes are read so if there was 482 an error we'll wait until we do read, then get it in 483 the read callback function. Until then, remove TEVENT_FD_READ 484 from the flags we're waiting for. */ 485 state->flags &= ~TEVENT_FD_READ; 486 TEVENT_FD_NOT_READABLE(fde); 487 488 /* If not writable, we're done. */ 489 if (!(flags & TEVENT_FD_WRITE)) { 490 return; 491 } 439 492 } 440 493 -
vendor/current/lib/async_req/async_sock.h
r414 r740 28 28 #include <tevent.h> 29 29 30 struct tevent_req *async_send_send(TALLOC_CTX *mem_ctx, 31 struct tevent_context *ev, 32 int fd, const void *buf, size_t len, 33 int flags); 34 ssize_t async_send_recv(struct tevent_req *req, int *perrno); 30 struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 31 int fd, const void *buf, size_t len, int flags, 32 const struct sockaddr_storage *addr); 33 ssize_t sendto_recv(struct tevent_req *req, int *perrno); 35 34 36 struct tevent_req *async_recv_send(TALLOC_CTX *mem_ctx, 37 struct tevent_context *ev, 38 int fd, void *buf, size_t len, int flags); 39 ssize_t async_recv_recv(struct tevent_req *req, int *perrno); 35 struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx, 36 struct tevent_context *ev, 37 int fd, void *buf, size_t len, int flags, 38 struct sockaddr_storage *addr, 39 socklen_t *addr_len); 40 ssize_t recvfrom_recv(struct tevent_req *req, int *perrno); 40 41 41 42 struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx,
Note:
See TracChangeset
for help on using the changeset viewer.