Changeset 745 for trunk/server/lib/async_req
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 1 deleted
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/lib/async_req/async_sock.c
r698 r745 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)) { … … 348 375 } 349 376 #endif 377 350 378 if (tevent_req_is_unix_error(req, &err)) { 351 379 *perrno = err; … … 368 396 size_t total_size; 369 397 uint16_t flags; 398 bool err_on_readability; 370 399 }; 371 400 … … 395 424 goto fail; 396 425 } 397 state->flags = TEVENT_FD_WRITE; 398 if (err_on_readability) { 399 state->flags |= TEVENT_FD_READ; 400 } 426 state->flags = TEVENT_FD_WRITE|TEVENT_FD_READ; 427 state->err_on_readability = err_on_readability; 401 428 402 429 if (queue == NULL) { … … 444 471 445 472 if ((state->flags & TEVENT_FD_READ) && (flags & TEVENT_FD_READ)) { 446 tevent_req_error(req, EPIPE); 447 return; 473 int ret, value; 474 475 if (state->err_on_readability) { 476 /* Readable and the caller wants an error on read. */ 477 tevent_req_error(req, EPIPE); 478 return; 479 } 480 481 /* Might be an error. Check if there are bytes to read */ 482 ret = ioctl(state->fd, FIONREAD, &value); 483 /* FIXME - should we also check 484 for ret == 0 and value == 0 here ? */ 485 if (ret == -1) { 486 /* There's an error. */ 487 tevent_req_error(req, EPIPE); 488 return; 489 } 490 /* A request for TEVENT_FD_READ will succeed from now and 491 forevermore until the bytes are read so if there was 492 an error we'll wait until we do read, then get it in 493 the read callback function. Until then, remove TEVENT_FD_READ 494 from the flags we're waiting for. */ 495 state->flags &= ~TEVENT_FD_READ; 496 TEVENT_FD_NOT_READABLE(fde); 497 498 /* If not writable, we're done. */ 499 if (!(flags & TEVENT_FD_WRITE)) { 500 return; 501 } 448 502 } 449 503 -
trunk/server/lib/async_req/async_sock.h
r414 r745 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.