summaryrefslogtreecommitdiff
path: root/lib/tsocket
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-04-02 21:06:27 +0200
committerStefan Metzmacher <metze@samba.org>2009-04-02 21:54:08 +0200
commit3bbad34a02350c96cb44d53da510c6273b6910d7 (patch)
tree8e0ea9f249f1f2280fa8e9cd420fbf1591658bec /lib/tsocket
parent7e1411b5c7afa8b47d76ddb1fb93973201bb08a8 (diff)
downloadsamba-3bbad34a02350c96cb44d53da510c6273b6910d7.tar.gz
samba-3bbad34a02350c96cb44d53da510c6273b6910d7.tar.bz2
samba-3bbad34a02350c96cb44d53da510c6273b6910d7.zip
tsocket: remove DGRAM support from tsocket_context
metze
Diffstat (limited to 'lib/tsocket')
-rw-r--r--lib/tsocket/config.mk2
-rw-r--r--lib/tsocket/tsocket.c15
-rw-r--r--lib/tsocket/tsocket.h32
-rw-r--r--lib/tsocket/tsocket_bsd.c72
-rw-r--r--lib/tsocket/tsocket_internal.h8
-rw-r--r--lib/tsocket/tsocket_recvfrom.c164
-rw-r--r--lib/tsocket/tsocket_sendto.c271
7 files changed, 0 insertions, 564 deletions
diff --git a/lib/tsocket/config.mk b/lib/tsocket/config.mk
index c35f0afd6f..2e05f544c9 100644
--- a/lib/tsocket/config.mk
+++ b/lib/tsocket/config.mk
@@ -5,8 +5,6 @@ LIBTSOCKET_OBJ_FILES = $(addprefix ../lib/tsocket/, \
tsocket.o \
tsocket_helpers.o \
tsocket_bsd.o \
- tsocket_recvfrom.o \
- tsocket_sendto.o \
tsocket_connect.o \
tsocket_writev.o \
tsocket_readv.o)
diff --git a/lib/tsocket/tsocket.c b/lib/tsocket/tsocket.c
index a8f3a3909b..076c6474a0 100644
--- a/lib/tsocket/tsocket.c
+++ b/lib/tsocket/tsocket.c
@@ -118,21 +118,6 @@ int tsocket_writev(struct tsocket_context *sock,
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);
diff --git a/lib/tsocket/tsocket.h b/lib/tsocket/tsocket.h
index ec891c34dd..8f69490012 100644
--- a/lib/tsocket/tsocket.h
+++ b/lib/tsocket/tsocket.h
@@ -34,7 +34,6 @@ struct iovec;
enum tsocket_type {
TSOCKET_TYPE_STREAM = 1,
- TSOCKET_TYPE_DGRAM,
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);
-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,
@@ -207,29 +198,6 @@ int _tdgram_unix_dgram_socket(const struct tsocket_address *local,
* 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);
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index db1fd38bdb..4ccaff46e3 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -615,9 +615,6 @@ static int tsocket_address_bsd_create_socket(const struct tsocket_address *addr,
}
bsd_type = SOCK_STREAM;
break;
- case TSOCKET_TYPE_DGRAM:
- bsd_type = SOCK_DGRAM;
- break;
default:
errno = EPROTONOSUPPORT;
return -1;
@@ -944,73 +941,6 @@ static int tsocket_context_bsd_writev_data(struct tsocket_context *sock,
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,
@@ -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,
- .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,
diff --git a/lib/tsocket/tsocket_internal.h b/lib/tsocket/tsocket_internal.h
index d1f240eba0..893394405f 100644
--- a/lib/tsocket/tsocket_internal.h
+++ b/lib/tsocket/tsocket_internal.h
@@ -57,14 +57,6 @@ struct tsocket_context_ops {
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,
diff --git a/lib/tsocket/tsocket_recvfrom.c b/lib/tsocket/tsocket_recvfrom.c
deleted file mode 100644
index 467738cfc2..0000000000
--- a/lib/tsocket/tsocket_recvfrom.c
+++ /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
index 9c0a76bf16..0000000000
--- a/lib/tsocket/tsocket_sendto.c
+++ /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;
-}
-