summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-01-11 15:19:32 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:43 -0500
commitffb8c82424a9d58a3dee1c42b7a64ab15711345b (patch)
treededb21add6e42d6109fd7aaa3db139c6505dbe1c /source4
parent9261f6e928bba21436dd3168db6db231e6a4e3ad (diff)
downloadsamba-ffb8c82424a9d58a3dee1c42b7a64ab15711345b.tar.gz
samba-ffb8c82424a9d58a3dee1c42b7a64ab15711345b.tar.bz2
samba-ffb8c82424a9d58a3dee1c42b7a64ab15711345b.zip
r4686: cerate a function to create a socket by specifying an socket_ops struct
metze (This used to be commit 894f402b01c8d4e0bef9c29697b8d13e5b9ea150)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/socket/socket.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index c2865cd9f0..9be6faf084 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -32,27 +32,23 @@ static int socket_destructor(void *ptr)
return 0;
}
-NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_context **new_sock, uint32_t flags)
+NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops, struct socket_context **new_sock, uint32_t flags)
{
NTSTATUS status;
- (*new_sock) = talloc_p(NULL, struct socket_context);
+ (*new_sock) = talloc(mem_ctx, struct socket_context);
if (!(*new_sock)) {
return NT_STATUS_NO_MEMORY;
}
- (*new_sock)->type = type;
+ (*new_sock)->type = ops->type;
(*new_sock)->state = SOCKET_STATE_UNDEFINED;
(*new_sock)->flags = flags;
(*new_sock)->fd = -1;
(*new_sock)->private_data = NULL;
- (*new_sock)->ops = socket_getops_byname(name, type);
- if (!(*new_sock)->ops) {
- talloc_free(*new_sock);
- return NT_STATUS_INVALID_PARAMETER;
- }
+ (*new_sock)->ops = ops;
status = (*new_sock)->ops->fn_init((*new_sock));
if (!NT_STATUS_IS_OK(status)) {
@@ -73,6 +69,18 @@ NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_co
return NT_STATUS_OK;
}
+NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_context **new_sock, uint32_t flags)
+{
+ const struct socket_ops *ops;
+
+ ops = socket_getops_byname(name, type);
+ if (!ops) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ return socket_create_with_ops(NULL, ops, new_sock, flags);
+}
+
void socket_destroy(struct socket_context *sock)
{
/* the close is handled by the destructor */