Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
1 deleted
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/async_req/async_sock.c

    r698 r745  
    3737#endif
    3838
    39 struct async_send_state {
     39struct sendto_state {
    4040        int fd;
    4141        const void *buf;
    4242        size_t len;
    4343        int flags;
     44        const struct sockaddr_storage *addr;
     45        socklen_t addr_len;
    4446        ssize_t sent;
    4547};
    4648
    47 static void async_send_handler(struct tevent_context *ev,
     49static void sendto_handler(struct tevent_context *ev,
    4850                               struct tevent_fd *fde,
    4951                               uint16_t flags, void *private_data);
    5052
    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)
     53struct 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)
    5556{
    5657        struct tevent_req *result;
    57         struct async_send_state *state;
     58        struct sendto_state *state;
    5859        struct tevent_fd *fde;
    5960
    60         result = tevent_req_create(mem_ctx, &state, struct async_send_state);
     61        result = tevent_req_create(mem_ctx, &state, struct sendto_state);
    6162        if (result == NULL) {
    6263                return result;
     
    6667        state->len = len;
    6768        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,
    7089                            result);
    7190        if (fde == NULL) {
     
    7695}
    7796
    78 static void async_send_handler(struct tevent_context *ev,
     97static void sendto_handler(struct tevent_context *ev,
    7998                               struct tevent_fd *fde,
    8099                               uint16_t flags, void *private_data)
     
    82101        struct tevent_req *req = talloc_get_type_abort(
    83102                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);
    88108        if ((state->sent == -1) && (errno == EINTR)) {
    89109                /* retry */
     
    97117}
    98118
    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);
     119ssize_t sendto_recv(struct tevent_req *req, int *perrno)
     120{
     121        struct sendto_state *state =
     122                tevent_req_data(req, struct sendto_state);
    103123
    104124        if (tevent_req_is_unix_error(req, perrno)) {
     
    108128}
    109129
    110 struct async_recv_state {
     130struct recvfrom_state {
    111131        int fd;
    112132        void *buf;
    113133        size_t len;
    114134        int flags;
     135        struct sockaddr_storage *addr;
     136        socklen_t *addr_len;
    115137        ssize_t received;
    116138};
    117139
    118 static void async_recv_handler(struct tevent_context *ev,
     140static void recvfrom_handler(struct tevent_context *ev,
    119141                               struct tevent_fd *fde,
    120142                               uint16_t flags, void *private_data);
    121143
    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)
     144struct 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)
    125149{
    126150        struct tevent_req *result;
    127         struct async_recv_state *state;
     151        struct recvfrom_state *state;
    128152        struct tevent_fd *fde;
    129153
    130         result = tevent_req_create(mem_ctx, &state, struct async_recv_state);
     154        result = tevent_req_create(mem_ctx, &state, struct recvfrom_state);
    131155        if (result == NULL) {
    132156                return result;
     
    136160        state->len = len;
    137161        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,
    140166                            result);
    141167        if (fde == NULL) {
     
    146172}
    147173
    148 static void async_recv_handler(struct tevent_context *ev,
     174static void recvfrom_handler(struct tevent_context *ev,
    149175                               struct tevent_fd *fde,
    150176                               uint16_t flags, void *private_data)
     
    152178        struct tevent_req *req = talloc_get_type_abort(
    153179                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);
    159186        if ((state->received == -1) && (errno == EINTR)) {
    160187                /* retry */
     
    172199}
    173200
    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);
     201ssize_t recvfrom_recv(struct tevent_req *req, int *perrno)
     202{
     203        struct recvfrom_state *state =
     204                tevent_req_data(req, struct recvfrom_state);
    178205
    179206        if (tevent_req_is_unix_error(req, perrno)) {
     
    348375        }
    349376#endif
     377
    350378        if (tevent_req_is_unix_error(req, &err)) {
    351379                *perrno = err;
     
    368396        size_t total_size;
    369397        uint16_t flags;
     398        bool err_on_readability;
    370399};
    371400
     
    395424                goto fail;
    396425        }
    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;
    401428
    402429        if (queue == NULL) {
     
    444471
    445472        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                }
    448502        }
    449503
  • trunk/server/lib/async_req/async_sock.h

    r414 r745  
    2828#include <tevent.h>
    2929
    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);
     30struct 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);
     33ssize_t sendto_recv(struct tevent_req *req, int *perrno);
    3534
    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);
     35struct 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);
     40ssize_t recvfrom_recv(struct tevent_req *req, int *perrno);
    4041
    4142struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx,
Note: See TracChangeset for help on using the changeset viewer.