summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/socket')
-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 */