summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-01-24 10:00:13 +0100
committerKai Blin <kai@samba.org>2009-01-28 11:35:32 +0100
commitab63bad94bfc378aca08d3314692de90e1aa1bf3 (patch)
tree931be3a7c4b7c2c28c836fdea89b42b8464fe0f9
parentc2a2006f8a8fdb8941158fc121ce551604cd1bae (diff)
downloadsamba-ab63bad94bfc378aca08d3314692de90e1aa1bf3.tar.gz
samba-ab63bad94bfc378aca08d3314692de90e1aa1bf3.tar.bz2
samba-ab63bad94bfc378aca08d3314692de90e1aa1bf3.zip
async_sock: Move to top level
-rw-r--r--lib/async_req/async_sock.c (renamed from source3/lib/async_sock.c)92
-rw-r--r--lib/async_req/async_sock.h (renamed from source3/include/async_sock.h)10
-rw-r--r--lib/async_req/config.mk2
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/includes.h2
5 files changed, 59 insertions, 49 deletions
diff --git a/source3/lib/async_sock.c b/lib/async_req/async_sock.c
index 73ff6f2870..7febc54fd4 100644
--- a/source3/lib/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -18,6 +18,15 @@
*/
#include "includes.h"
+#include "lib/talloc/talloc.h"
+#include "lib/tevent/tevent.h"
+#include "lib/async_req/async_req.h"
+#include "lib/async_req/async_sock.h"
+#include <fcntl.h>
+
+#ifndef TALLOC_FREE
+#define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
+#endif
/**
* Discriminator for async_syscall_state
@@ -36,7 +45,7 @@ enum async_syscall_type {
struct async_syscall_state {
enum async_syscall_type syscall_type;
- struct fd_event *fde;
+ struct tevent_fd *fde;
union {
struct param_send {
@@ -99,7 +108,7 @@ struct async_syscall_state {
*/
static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
+ struct tevent_context *ev,
enum async_syscall_type type,
struct async_syscall_state **pstate)
{
@@ -125,7 +134,7 @@ static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
* @param[in] ev The event context to work from
* @param[in] type Which syscall will this be
* @param[in] fd The file descriptor we work on
- * @param[in] fde_flags EVENT_FD_READ/WRITE -- what are we interested in?
+ * @param[in] fde_flags TEVENT_FD_READ/WRITE -- what are we interested in?
* @param[in] fde_cb The callback function for the file descriptor event
* @param[in] pstate Where to put the newly created private_data state
* @retval The new request
@@ -137,12 +146,12 @@ static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
static struct async_req *async_fde_syscall_new(
TALLOC_CTX *mem_ctx,
- struct event_context *ev,
+ struct tevent_context *ev,
enum async_syscall_type type,
int fd,
uint16_t fde_flags,
- void (*fde_cb)(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+ void (*fde_cb)(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv),
struct async_syscall_state **pstate)
{
@@ -154,7 +163,7 @@ static struct async_req *async_fde_syscall_new(
return NULL;
}
- state->fde = event_add_fd(ev, state, fd, fde_flags, fde_cb, result);
+ state->fde = tevent_add_fd(ev, state, fd, fde_flags, fde_cb, result);
if (state->fde == NULL) {
TALLOC_FREE(result);
return NULL;
@@ -215,12 +224,12 @@ int async_syscall_result_int(struct async_req *req, int *perrno)
* fde event handler for the "send" syscall
* @param[in] ev The event context that sent us here
* @param[in] fde The file descriptor event associated with the send
- * @param[in] flags Can only be EVENT_FD_WRITE here
+ * @param[in] flags Can only be TEVENT_FD_WRITE here
* @param[in] priv private data, "struct async_req *" in this case
*/
-static void async_send_callback(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_send_callback(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv)
{
struct async_req *req = talloc_get_type_abort(
@@ -255,7 +264,7 @@ static void async_send_callback(struct event_context *ev,
* This function is a direct counterpart of send(2)
*/
-struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *async_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, const void *buffer, size_t length,
int flags)
{
@@ -264,7 +273,7 @@ struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
result = async_fde_syscall_new(
mem_ctx, ev, ASYNC_SYSCALL_SEND,
- fd, EVENT_FD_WRITE, async_send_callback,
+ fd, TEVENT_FD_WRITE, async_send_callback,
&state);
if (result == NULL) {
return NULL;
@@ -282,12 +291,12 @@ struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
* fde event handler for the "sendall" syscall group
* @param[in] ev The event context that sent us here
* @param[in] fde The file descriptor event associated with the send
- * @param[in] flags Can only be EVENT_FD_WRITE here
+ * @param[in] flags Can only be TEVENT_FD_WRITE here
* @param[in] priv private data, "struct async_req *" in this case
*/
-static void async_sendall_callback(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_sendall_callback(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv)
{
struct async_req *req = talloc_get_type_abort(
@@ -301,7 +310,8 @@ static void async_sendall_callback(struct event_context *ev,
return;
}
- state->result.result_ssize_t = send(p->fd, (char *)p->buffer + p->sent,
+ state->result.result_ssize_t = send(p->fd,
+ (const char *)p->buffer + p->sent,
p->length - p->sent, p->flags);
state->sys_errno = errno;
@@ -340,7 +350,7 @@ static void async_sendall_callback(struct event_context *ev,
* "length" bytes
*/
-struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, const void *buffer, size_t length,
int flags)
{
@@ -349,7 +359,7 @@ struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
result = async_fde_syscall_new(
mem_ctx, ev, ASYNC_SYSCALL_SENDALL,
- fd, EVENT_FD_WRITE, async_sendall_callback,
+ fd, TEVENT_FD_WRITE, async_sendall_callback,
&state);
if (result == NULL) {
return NULL;
@@ -373,12 +383,12 @@ NTSTATUS sendall_recv(struct async_req *req)
* fde event handler for the "recv" syscall
* @param[in] ev The event context that sent us here
* @param[in] fde The file descriptor event associated with the recv
- * @param[in] flags Can only be EVENT_FD_READ here
+ * @param[in] flags Can only be TEVENT_FD_READ here
* @param[in] priv private data, "struct async_req *" in this case
*/
-static void async_recv_callback(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_recv_callback(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv)
{
struct async_req *req = talloc_get_type_abort(
@@ -413,7 +423,7 @@ static void async_recv_callback(struct event_context *ev,
* This function is a direct counterpart of recv(2)
*/
-struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, void *buffer, size_t length,
int flags)
{
@@ -422,7 +432,7 @@ struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev,
result = async_fde_syscall_new(
mem_ctx, ev, ASYNC_SYSCALL_RECV,
- fd, EVENT_FD_READ, async_recv_callback,
+ fd, TEVENT_FD_READ, async_recv_callback,
&state);
if (result == NULL) {
@@ -441,12 +451,12 @@ struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev,
* fde event handler for the "recvall" syscall group
* @param[in] ev The event context that sent us here
* @param[in] fde The file descriptor event associated with the recv
- * @param[in] flags Can only be EVENT_FD_READ here
+ * @param[in] flags Can only be TEVENT_FD_READ here
* @param[in] priv private data, "struct async_req *" in this case
*/
-static void async_recvall_callback(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_recvall_callback(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv)
{
struct async_req *req = talloc_get_type_abort(
@@ -499,7 +509,7 @@ static void async_recvall_callback(struct event_context *ev,
* async_recvall will call recv(2) until "length" bytes are received
*/
-struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, void *buffer, size_t length,
int flags)
{
@@ -508,7 +518,7 @@ struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
result = async_fde_syscall_new(
mem_ctx, ev, ASYNC_SYSCALL_RECVALL,
- fd, EVENT_FD_READ, async_recvall_callback,
+ fd, TEVENT_FD_READ, async_recvall_callback,
&state);
if (result == NULL) {
return NULL;
@@ -535,8 +545,8 @@ struct async_connect_state {
long old_sockflags;
};
-static void async_connect_connected(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_connect_connected(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv);
/**
@@ -553,13 +563,13 @@ static void async_connect_connected(struct event_context *ev,
*/
struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
+ struct tevent_context *ev,
int fd, const struct sockaddr *address,
socklen_t address_len)
{
struct async_req *result;
struct async_connect_state *state;
- struct fd_event *fde;
+ struct tevent_fd *fde;
NTSTATUS status;
if (!async_req_setup(mem_ctx, &result, &state,
@@ -575,7 +585,7 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
state->fd = fd;
state->sys_errno = 0;
- state->old_sockflags = sys_fcntl_long(fd, F_GETFL, 0);
+ state->old_sockflags = fcntl(fd, F_GETFL, 0);
if (state->old_sockflags == -1) {
goto post_errno;
}
@@ -604,7 +614,7 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
goto post_errno;
}
- fde = event_add_fd(ev, state, fd, EVENT_FD_READ | EVENT_FD_WRITE,
+ fde = tevent_add_fd(ev, state, fd, TEVENT_FD_READ | TEVENT_FD_WRITE,
async_connect_connected, result);
if (fde == NULL) {
status = NT_STATUS_NO_MEMORY;
@@ -616,7 +626,7 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
state->sys_errno = errno;
status = map_nt_error_from_unix(state->sys_errno);
post_status:
- sys_fcntl_long(fd, F_SETFL, state->old_sockflags);
+ fcntl(fd, F_SETFL, state->old_sockflags);
if (!async_post_status(result, ev, status)) {
goto fail;
}
@@ -634,8 +644,8 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
* @param[in] priv private data, "struct async_req *" in this case
*/
-static void async_connect_connected(struct event_context *ev,
- struct fd_event *fde, uint16_t flags,
+static void async_connect_connected(struct tevent_context *ev,
+ struct tevent_fd *fde, uint16_t flags,
void *priv)
{
struct async_req *req = talloc_get_type_abort(
@@ -650,8 +660,8 @@ static void async_connect_connected(struct event_context *ev,
* successful connect, the socket is only writable. Upon an
* error, it's both readable and writable.
*/
- if ((flags & (EVENT_FD_READ|EVENT_FD_WRITE))
- == (EVENT_FD_READ|EVENT_FD_WRITE)) {
+ if ((flags & (TEVENT_FD_READ|TEVENT_FD_WRITE))
+ == (TEVENT_FD_READ|TEVENT_FD_WRITE)) {
int sockerr;
socklen_t err_len = sizeof(sockerr);
@@ -664,7 +674,7 @@ static void async_connect_connected(struct event_context *ev,
DEBUG(10, ("connect returned %s\n", strerror(errno)));
- sys_fcntl_long(state->fd, F_SETFL, state->old_sockflags);
+ fcntl(state->fd, F_SETFL, state->old_sockflags);
async_req_error(req, map_nt_error_from_unix(state->sys_errno));
return;
}
@@ -679,7 +689,7 @@ NTSTATUS async_connect_recv(struct async_req *req, int *perrno)
req->private_data, struct async_connect_state);
NTSTATUS status;
- sys_fcntl_long(state->fd, F_SETFL, state->old_sockflags);
+ fcntl(state->fd, F_SETFL, state->old_sockflags);
*perrno = state->sys_errno;
diff --git a/source3/include/async_sock.h b/lib/async_req/async_sock.h
index c6f95d64d5..fd41acacbb 100644
--- a/source3/include/async_sock.h
+++ b/lib/async_req/async_sock.h
@@ -26,24 +26,24 @@ ssize_t async_syscall_result_ssize_t(struct async_req *req, int *perrno);
size_t async_syscall_result_size_t(struct async_req *req, int *perrno);
int async_syscall_result_int(struct async_req *req, int *perrno);
-struct async_req *async_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *async_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, const void *buffer, size_t length,
int flags);
-struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *async_recv(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, void *buffer, size_t length,
int flags);
struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
+ struct tevent_context *ev,
int fd, const struct sockaddr *address,
socklen_t address_len);
NTSTATUS async_connect_recv(struct async_req *req, int *perrno);
-struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *sendall_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, const void *buffer, size_t length,
int flags);
NTSTATUS sendall_recv(struct async_req *req);
-struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct async_req *recvall_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int fd, void *buffer, size_t length,
int flags);
NTSTATUS recvall_recv(struct async_req *req);
diff --git a/lib/async_req/config.mk b/lib/async_req/config.mk
index 08d5288a48..8cc594082c 100644
--- a/lib/async_req/config.mk
+++ b/lib/async_req/config.mk
@@ -1,3 +1,3 @@
[SUBSYSTEM::LIBASYNC_REQ]
-LIBASYNC_REQ_OBJ_FILES = $(addprefix ../lib/async_req/, async_req.o)
+LIBASYNC_REQ_OBJ_FILES = $(addprefix ../lib/async_req/, async_req.o async_sock.o)
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 607044fd83..e786a81efa 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -344,7 +344,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o \
lib/interfaces.o lib/memcache.o \
lib/util_transfer_file.o ../lib/async_req/async_req.o \
- lib/async_sock.o \
+ ../lib/async_req/async_sock.o \
$(TDB_LIB_OBJ) \
$(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
lib/interface.o lib/pidfile.o \
diff --git a/source3/include/includes.h b/source3/include/includes.h
index ea856f1c16..7b0b270f60 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -649,7 +649,7 @@ struct smb_iconv_convenience *lp_iconv_convenience(void *lp_ctx);
#include "memcache.h"
#include "../lib/async_req/async_req.h"
#include "async_smb.h"
-#include "async_sock.h"
+#include "../lib/async_req/async_sock.h"
#include "services.h"
#include "eventlog.h"