tsocket: remove DGRAM support from tsocket_context
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Apr 2009 19:06:27 +0000 (21:06 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 2 Apr 2009 19:54:08 +0000 (21:54 +0200)
metze

lib/tsocket/config.mk
lib/tsocket/tsocket.c
lib/tsocket/tsocket.h
lib/tsocket/tsocket_bsd.c
lib/tsocket/tsocket_internal.h
lib/tsocket/tsocket_recvfrom.c [deleted file]
lib/tsocket/tsocket_sendto.c [deleted file]

index c35f0afd6fa28bbea31f36dbc36c10a934ba83b7..2e05f544c96f65ace78ab33a62d5ccfbd1e9107e 100644 (file)
@@ -5,8 +5,6 @@ LIBTSOCKET_OBJ_FILES = $(addprefix ../lib/tsocket/, \
                                        tsocket.o \
                                        tsocket_helpers.o \
                                        tsocket_bsd.o \
                                        tsocket.o \
                                        tsocket_helpers.o \
                                        tsocket_bsd.o \
-                                       tsocket_recvfrom.o \
-                                       tsocket_sendto.o \
                                        tsocket_connect.o \
                                        tsocket_writev.o \
                                        tsocket_readv.o)
                                        tsocket_connect.o \
                                        tsocket_writev.o \
                                        tsocket_readv.o)
index a8f3a3909b5d6797ea54713e52322d71e7e98638..076c6474a09f126e9f62afb65ceb02f7202b3408 100644 (file)
@@ -118,21 +118,6 @@ int tsocket_writev(struct tsocket_context *sock,
        return sock->ops->writev_data(sock, vector, count);
 }
 
        return sock->ops->writev_data(sock, vector, count);
 }
 
-ssize_t tsocket_recvfrom(struct tsocket_context *sock,
-                        uint8_t *data, size_t len,
-                        TALLOC_CTX *addr_ctx,
-                        struct tsocket_address **src_addr)
-{
-       return sock->ops->recvfrom_data(sock, data, len, addr_ctx, src_addr);
-}
-
-ssize_t tsocket_sendto(struct tsocket_context *sock,
-                      const uint8_t *data, size_t len,
-                      const struct tsocket_address *dest_addr)
-{
-       return sock->ops->sendto_data(sock, data, len, dest_addr);
-}
-
 int tsocket_get_status(const struct tsocket_context *sock)
 {
        return sock->ops->get_status(sock);
 int tsocket_get_status(const struct tsocket_context *sock)
 {
        return sock->ops->get_status(sock);
index ec891c34dd2b6b4d794fba939c0f173239674599..8f69490012e223ea33c7642ba5780a0795bc0f1e 100644 (file)
@@ -34,7 +34,6 @@ struct iovec;
 
 enum tsocket_type {
        TSOCKET_TYPE_STREAM = 1,
 
 enum tsocket_type {
        TSOCKET_TYPE_STREAM = 1,
-       TSOCKET_TYPE_DGRAM,
        TSOCKET_TYPE_MESSAGE
 };
 
        TSOCKET_TYPE_MESSAGE
 };
 
@@ -68,14 +67,6 @@ int tsocket_readv(struct tsocket_context *sock,
 int tsocket_writev(struct tsocket_context *sock,
                   const struct iovec *vector, size_t count);
 
 int tsocket_writev(struct tsocket_context *sock,
                   const struct iovec *vector, size_t count);
 
-ssize_t tsocket_recvfrom(struct tsocket_context *sock,
-                        uint8_t *data, size_t len,
-                        TALLOC_CTX *addr_ctx,
-                        struct tsocket_address **src_addr);
-ssize_t tsocket_sendto(struct tsocket_context *sock,
-                      const uint8_t *data, size_t len,
-                      const struct tsocket_address *dest_addr);
-
 int tsocket_get_status(const struct tsocket_context *sock);
 
 int _tsocket_get_local_address(const struct tsocket_context *sock,
 int tsocket_get_status(const struct tsocket_context *sock);
 
 int _tsocket_get_local_address(const struct tsocket_context *sock,
@@ -207,29 +198,6 @@ int _tdgram_unix_dgram_socket(const struct tsocket_address *local,
  * Async helpers
  */
 
  * Async helpers
  */
 
-struct tevent_req *tsocket_recvfrom_send(struct tsocket_context *sock,
-                                        TALLOC_CTX *mem_ctx);
-ssize_t tsocket_recvfrom_recv(struct tevent_req *req,
-                             int *perrno,
-                             TALLOC_CTX *mem_ctx,
-                             uint8_t **buf,
-                             struct tsocket_address **src);
-
-struct tevent_req *tsocket_sendto_send(struct tsocket_context *sock,
-                                      TALLOC_CTX *mem_ctx,
-                                      const uint8_t *buf,
-                                      size_t len,
-                                      const struct tsocket_address *dst);
-ssize_t tsocket_sendto_recv(struct tevent_req *req, int *perrno);
-
-struct tevent_req *tsocket_sendto_queue_send(TALLOC_CTX *mem_ctx,
-                                            struct tsocket_context *sock,
-                                            struct tevent_queue *queue,
-                                            const uint8_t *buf,
-                                            size_t len,
-                                            struct tsocket_address *dst);
-ssize_t tsocket_sendto_queue_recv(struct tevent_req *req, int *perrno);
-
 struct tevent_req *tsocket_connect_send(struct tsocket_context *sock,
                                        TALLOC_CTX *mem_ctx,
                                        const struct tsocket_address *dst);
 struct tevent_req *tsocket_connect_send(struct tsocket_context *sock,
                                        TALLOC_CTX *mem_ctx,
                                        const struct tsocket_address *dst);
index db1fd38bdb0bb5fa161b734a978316b99a00b62e..4ccaff46e3b460c89d6c5bef7179d7fca718bbfc 100644 (file)
@@ -615,9 +615,6 @@ static int tsocket_address_bsd_create_socket(const struct tsocket_address *addr,
                }
                bsd_type = SOCK_STREAM;
                break;
                }
                bsd_type = SOCK_STREAM;
                break;
-       case TSOCKET_TYPE_DGRAM:
-               bsd_type = SOCK_DGRAM;
-               break;
        default:
                errno = EPROTONOSUPPORT;
                return -1;
        default:
                errno = EPROTONOSUPPORT;
                return -1;
@@ -944,73 +941,6 @@ static int tsocket_context_bsd_writev_data(struct tsocket_context *sock,
        return ret;
 }
 
        return ret;
 }
 
-static ssize_t tsocket_context_bsd_recvfrom_data(struct tsocket_context *sock,
-                                                 uint8_t *data, size_t len,
-                                                 TALLOC_CTX *addr_ctx,
-                                                 struct tsocket_address **remote)
-{
-       struct tsocket_context_bsd *bsds = talloc_get_type(sock->private_data,
-                                          struct tsocket_context_bsd);
-       struct tsocket_address *addr = NULL;
-       struct tsocket_address_bsd *bsda;
-       ssize_t ret;
-       struct sockaddr *sa = NULL;
-       socklen_t sa_len = 0;
-
-       if (remote) {
-               addr = tsocket_address_create(addr_ctx,
-                                             &tsocket_address_bsd_ops,
-                                             &bsda,
-                                             struct tsocket_address_bsd,
-                                             __location__ "recvfrom");
-               if (!addr) {
-                       return -1;
-               }
-
-               ZERO_STRUCTP(bsda);
-
-               sa = &bsda->u.sa;
-               sa_len = sizeof(bsda->u.ss);
-       }
-
-       ret = recvfrom(bsds->fd, data, len, 0, sa, &sa_len);
-       if (ret < 0) {
-               int saved_errno = errno;
-               talloc_free(addr);
-               errno = saved_errno;
-               return ret;
-       }
-
-       if (remote) {
-               *remote = addr;
-       }
-       return ret;
-}
-
-static ssize_t tsocket_context_bsd_sendto_data(struct tsocket_context *sock,
-                                               const uint8_t *data, size_t len,
-                                               const struct tsocket_address *remote)
-{
-       struct tsocket_context_bsd *bsds = talloc_get_type(sock->private_data,
-                                          struct tsocket_context_bsd);
-       struct sockaddr *sa = NULL;
-       socklen_t sa_len = 0;
-       ssize_t ret;
-
-       if (remote) {
-               struct tsocket_address_bsd *bsda =
-                       talloc_get_type(remote->private_data,
-                       struct tsocket_address_bsd);
-
-               sa = &bsda->u.sa;
-               sa_len = sizeof(bsda->u.ss);
-       }
-
-       ret = sendto(bsds->fd, data, len, 0, sa, sa_len);
-
-       return ret;
-}
-
 static int tsocket_context_bsd_get_status(const struct tsocket_context *sock)
 {
        struct tsocket_context_bsd *bsds = talloc_get_type(sock->private_data,
 static int tsocket_context_bsd_get_status(const struct tsocket_context *sock)
 {
        struct tsocket_context_bsd *bsds = talloc_get_type(sock->private_data,
@@ -1272,8 +1202,6 @@ static const struct tsocket_context_ops tsocket_context_bsd_ops = {
        .pending_data           = tsocket_context_bsd_pending_data,
        .readv_data             = tsocket_context_bsd_readv_data,
        .writev_data            = tsocket_context_bsd_writev_data,
        .pending_data           = tsocket_context_bsd_pending_data,
        .readv_data             = tsocket_context_bsd_readv_data,
        .writev_data            = tsocket_context_bsd_writev_data,
-       .recvfrom_data          = tsocket_context_bsd_recvfrom_data,
-       .sendto_data            = tsocket_context_bsd_sendto_data,
 
        .get_status             = tsocket_context_bsd_get_status,
        .get_local_address      = tsocket_context_bsd_get_local_address,
 
        .get_status             = tsocket_context_bsd_get_status,
        .get_local_address      = tsocket_context_bsd_get_local_address,
index d1f240eba0e234a30932b8596d29945c738f3b44..893394405f87db0b307800dbe8f77381a7047f83 100644 (file)
@@ -57,14 +57,6 @@ struct tsocket_context_ops {
        int (*writev_data)(struct tsocket_context *sock,
                           const struct iovec *vector, size_t count);
 
        int (*writev_data)(struct tsocket_context *sock,
                           const struct iovec *vector, size_t count);
 
-       ssize_t (*recvfrom_data)(struct tsocket_context *sock,
-                                uint8_t *data, size_t len,
-                                TALLOC_CTX *addr_ctx,
-                                struct tsocket_address **remote_addr);
-       ssize_t (*sendto_data)(struct tsocket_context *sock,
-                              const uint8_t *data, size_t len,
-                              const struct tsocket_address *remote_addr);
-
        /* info */
        int (*get_status)(const struct tsocket_context *sock);
        int (*get_local_address)(const struct tsocket_context *sock,
        /* info */
        int (*get_status)(const struct tsocket_context *sock);
        int (*get_local_address)(const struct tsocket_context *sock,
diff --git a/lib/tsocket/tsocket_recvfrom.c b/lib/tsocket/tsocket_recvfrom.c
deleted file mode 100644 (file)
index 467738c..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-
-   Copyright (C) Stefan Metzmacher 2009
-
-     ** NOTE! The following LGPL license applies to the tevent
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "replace.h"
-#include "system/network.h"
-#include "tsocket.h"
-#include "tsocket_internal.h"
-
-struct tsocket_recvfrom_state {
-       /* this structs are owned by the caller */
-       struct {
-               struct tsocket_context *sock;
-       } caller;
-
-       uint8_t *buf;
-       size_t len;
-       struct tsocket_address *src;
-};
-
-static int tsocket_recvfrom_state_destructor(struct tsocket_recvfrom_state *state)
-{
-       if (state->caller.sock) {
-               tsocket_set_readable_handler(state->caller.sock, NULL, NULL);
-       }
-       ZERO_STRUCT(state->caller);
-
-       return 0;
-}
-
-static void tsocket_recvfrom_handler(struct tsocket_context *sock,
-                                    void *private_data);
-
-struct tevent_req *tsocket_recvfrom_send(struct tsocket_context *sock,
-                                        TALLOC_CTX *mem_ctx)
-{
-       struct tevent_req *req;
-       struct tsocket_recvfrom_state *state;
-       int ret;
-       int err;
-       bool dummy;
-
-       req = tevent_req_create(mem_ctx, &state,
-                               struct tsocket_recvfrom_state);
-       if (!req) {
-               return NULL;
-       }
-
-       state->caller.sock      = sock;
-       state->buf              = NULL;
-       state->len              = 0;
-       state->src              = NULL;
-
-       talloc_set_destructor(state, tsocket_recvfrom_state_destructor);
-
-       ret = tsocket_set_readable_handler(sock,
-                                          tsocket_recvfrom_handler,
-                                          req);
-       err = tsocket_error_from_errno(ret, errno, &dummy);
-       if (tevent_req_error(req, err)) {
-               goto post;
-       }
-
-       return req;
-
- post:
-       return tevent_req_post(req, sock->event.ctx);
-}
-
-static void tsocket_recvfrom_handler(struct tsocket_context *sock,
-                                    void *private_data)
-{
-       struct tevent_req *req = talloc_get_type(private_data,
-                                struct tevent_req);
-       struct tsocket_recvfrom_state *state = tevent_req_data(req,
-                                              struct tsocket_recvfrom_state);
-       ssize_t ret;
-       int err;
-       bool retry;
-
-       ret = tsocket_pending(state->caller.sock);
-       if (ret == 0) {
-               /* retry later */
-               return;
-       }
-       err = tsocket_error_from_errno(ret, errno, &retry);
-       if (retry) {
-               /* retry later */
-               return;
-       }
-       if (tevent_req_error(req, err)) {
-               return;
-       }
-
-       state->buf = talloc_array(state, uint8_t, ret);
-       if (tevent_req_nomem(state->buf, req)) {
-               return;
-       }
-       state->len = ret;
-
-       ret = tsocket_recvfrom(state->caller.sock,
-                              state->buf,
-                              state->len,
-                              state,
-                              &state->src);
-       err = tsocket_error_from_errno(ret, errno, &retry);
-       if (retry) {
-               /* retry later */
-               return;
-       }
-       if (tevent_req_error(req, err)) {
-               return;
-       }
-
-       if (ret != state->len) {
-               tevent_req_error(req, EIO);
-               return;
-       }
-
-       tevent_req_done(req);
-}
-
-ssize_t tsocket_recvfrom_recv(struct tevent_req *req,
-                             int *perrno,
-                             TALLOC_CTX *mem_ctx,
-                             uint8_t **buf,
-                             struct tsocket_address **src)
-{
-       struct tsocket_recvfrom_state *state = tevent_req_data(req,
-                                              struct tsocket_recvfrom_state);
-       ssize_t ret;
-
-       ret = tsocket_simple_int_recv(req, perrno);
-       if (ret == 0) {
-               *buf = talloc_move(mem_ctx, &state->buf);
-               ret = state->len;
-               if (src) {
-                       *src = talloc_move(mem_ctx, &state->src);
-               }
-       }
-
-       tevent_req_received(req);
-       return ret;
-}
-
diff --git a/lib/tsocket/tsocket_sendto.c b/lib/tsocket/tsocket_sendto.c
deleted file mode 100644 (file)
index 9c0a76b..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-
-   Copyright (C) Stefan Metzmacher 2009
-
-     ** NOTE! The following LGPL license applies to the tevent
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "replace.h"
-#include "system/network.h"
-#include "tsocket.h"
-#include "tsocket_internal.h"
-
-struct tsocket_sendto_state {
-       /* this structs are owned by the caller */
-       struct {
-               struct tsocket_context *sock;
-               const uint8_t *buf;
-               size_t len;
-               const struct tsocket_address *dst;
-       } caller;
-
-       ssize_t ret;
-};
-
-static int tsocket_sendto_state_destructor(struct tsocket_sendto_state *state)
-{
-       if (state->caller.sock) {
-               tsocket_set_writeable_handler(state->caller.sock, NULL, NULL);
-       }
-       ZERO_STRUCT(state->caller);
-
-       return 0;
-}
-
-static void tsocket_sendto_handler(struct tsocket_context *sock,
-                                  void *private_data);
-
-struct tevent_req *tsocket_sendto_send(struct tsocket_context *sock,
-                                      TALLOC_CTX *mem_ctx,
-                                      const uint8_t *buf,
-                                      size_t len,
-                                      const struct tsocket_address *dst)
-{
-       struct tevent_req *req;
-       struct tsocket_sendto_state *state;
-       int ret;
-       int err;
-       bool dummy;
-
-       req = tevent_req_create(mem_ctx, &state,
-                               struct tsocket_sendto_state);
-       if (!req) {
-               return NULL;
-       }
-
-       state->caller.sock      = sock;
-       state->caller.buf       = buf;
-       state->caller.len       = len;
-       state->caller.dst       = dst;
-       state->ret              = -1;
-
-       /*
-        * this is a fast path, not waiting for the
-        * socket to become explicit writeable gains
-        * about 10%-20% performance in benchmark tests.
-        */
-       tsocket_sendto_handler(sock, req);
-       if (!tevent_req_is_in_progress(req)) {
-               goto post;
-       }
-
-       talloc_set_destructor(state, tsocket_sendto_state_destructor);
-
-       ret = tsocket_set_writeable_handler(sock,
-                                           tsocket_sendto_handler,
-                                           req);
-       err = tsocket_error_from_errno(ret, errno, &dummy);
-       if (tevent_req_error(req, err)) {
-               goto post;
-       }
-
-       return req;
-
- post:
-       return tevent_req_post(req, sock->event.ctx);
-}
-
-static void tsocket_sendto_handler(struct tsocket_context *sock,
-                                  void *private_data)
-{
-       struct tevent_req *req = talloc_get_type(private_data,
-                                struct tevent_req);
-       struct tsocket_sendto_state *state = tevent_req_data(req,
-                                            struct tsocket_sendto_state);
-       ssize_t ret;
-       int err;
-       bool retry;
-
-       ret = tsocket_sendto(state->caller.sock,
-                            state->caller.buf,
-                            state->caller.len,
-                            state->caller.dst);
-       err = tsocket_error_from_errno(ret, errno, &retry);
-       if (retry) {
-               /* retry later */
-               return;
-       }
-       if (tevent_req_error(req, err)) {
-               return;
-       }
-
-       state->ret = ret;
-
-       tevent_req_done(req);
-}
-
-ssize_t tsocket_sendto_recv(struct tevent_req *req, int *perrno)
-{
-       struct tsocket_sendto_state *state = tevent_req_data(req,
-                                            struct tsocket_sendto_state);
-       ssize_t ret;
-
-       ret = tsocket_simple_int_recv(req, perrno);
-       if (ret == 0) {
-               ret = state->ret;
-       }
-
-       tevent_req_received(req);
-       return ret;
-}
-
-struct tsocket_sendto_queue_state {
-       /* this structs are owned by the caller */
-       struct {
-               struct tsocket_context *sock;
-               const uint8_t *buf;
-               size_t len;
-               const struct tsocket_address *dst;
-       } caller;
-       ssize_t ret;
-};
-
-static void tsocket_sendto_queue_trigger(struct tevent_req *req,
-                                        void *private_data);
-static void tsocket_sendto_queue_done(struct tevent_req *subreq);
-
-/**
- * @brief Queue a dgram blob for sending through the socket
- * @param[in] mem_ctx  The memory context for the result
- * @param[in] sock     The socket to send the message buffer
- * @param[in] queue    The existing dgram queue
- * @param[in] buf      The message buffer
- * @param[in] len      The message length
- * @param[in] dst      The destination socket address
- * @retval             The async request handle
- *
- * This function queues a blob for sending to destination through an existing
- * dgram socket. The async callback is triggered when the whole blob is
- * delivered to the underlying system socket.
- *
- * The caller needs to make sure that all non-scalar input parameters hang
- * arround for the whole lifetime of the request.
- */
-struct tevent_req *tsocket_sendto_queue_send(TALLOC_CTX *mem_ctx,
-                                            struct tsocket_context *sock,
-                                            struct tevent_queue *queue,
-                                            const uint8_t *buf,
-                                            size_t len,
-                                            struct tsocket_address *dst)
-{
-       struct tevent_req *req;
-       struct tsocket_sendto_queue_state *state;
-       bool ok;
-
-       req = tevent_req_create(mem_ctx, &state,
-                               struct tsocket_sendto_queue_state);
-       if (!req) {
-               return NULL;
-       }
-
-       state->caller.sock      = sock;
-       state->caller.buf       = buf;
-       state->caller.len       = len;
-       state->caller.dst       = dst;
-       state->ret              = -1;
-
-       ok = tevent_queue_add(queue,
-                             sock->event.ctx,
-                             req,
-                             tsocket_sendto_queue_trigger,
-                             NULL);
-       if (!ok) {
-               tevent_req_nomem(NULL, req);
-               goto post;
-       }
-
-       return req;
-
- post:
-       return tevent_req_post(req, sock->event.ctx);
-}
-
-static void tsocket_sendto_queue_trigger(struct tevent_req *req,
-                                        void *private_data)
-{
-       struct tsocket_sendto_queue_state *state = tevent_req_data(req,
-                                       struct tsocket_sendto_queue_state);
-       struct tevent_req *subreq;
-
-       subreq = tsocket_sendto_send(state->caller.sock,
-                                    state,
-                                    state->caller.buf,
-                                    state->caller.len,
-                                    state->caller.dst);
-       if (tevent_req_nomem(subreq, req)) {
-               return;
-       }
-       tevent_req_set_callback(subreq, tsocket_sendto_queue_done ,req);
-}
-
-static void tsocket_sendto_queue_done(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(subreq,
-                                struct tevent_req);
-       struct tsocket_sendto_queue_state *state = tevent_req_data(req,
-                                       struct tsocket_sendto_queue_state);
-       ssize_t ret;
-       int sys_errno;
-
-       ret = tsocket_sendto_recv(subreq, &sys_errno);
-       talloc_free(subreq);
-       if (ret == -1) {
-               tevent_req_error(req, sys_errno);
-               return;
-       }
-       state->ret = ret;
-
-       tevent_req_done(req);
-}
-
-ssize_t tsocket_sendto_queue_recv(struct tevent_req *req, int *perrno)
-{
-       struct tsocket_sendto_queue_state *state = tevent_req_data(req,
-                                       struct tsocket_sendto_queue_state);
-       ssize_t ret;
-
-       ret = tsocket_simple_int_recv(req, perrno);
-       if (ret == 0) {
-               ret = state->ret;
-       }
-
-       tevent_req_received(req);
-       return ret;
-}
-