This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Triton Repository".
The branch, master has been updated
via 9a1189a2a334461307c4bb8220aff2c27ec878e4 (commit)
from de851668852c0fcf17fb196b28e571d3f850251e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9a1189a2a334461307c4bb8220aff2c27ec878e4
Author: Phil Carns <carns(a)mcs.anl.gov>
Date: Fri Jun 3 14:51:56 2011 -0400
vim/emacs comment blocks, fix indentation
-----------------------------------------------------------------------
Summary of changes:
code/src/common/resources/aesocket/aesocket.c | 205 ++++++++++++----------
code/src/common/resources/aesocket/aesocket.hae | 22 ++-
code/src/socket/test/echo-server.ae | 196 ++++++++++++----------
code/src/socket/triton-socket.ae | 128 ++++++++------
code/src/socket/triton-socket.hae | 28 +++-
5 files changed, 331 insertions(+), 248 deletions(-)
Diff of changes:
diff --git a/code/src/common/resources/aesocket/aesocket.c b/code/src/common/resources/aesocket/aesocket.c
index f0522cb..1c18de6 100644
--- a/code/src/common/resources/aesocket/aesocket.c
+++ b/code/src/common/resources/aesocket/aesocket.c
@@ -7,7 +7,7 @@
#include <assert.h>
#ifndef __AESOP_LIBEV
-# error Socket resource requires libev for now!
+#error Socket resource requires libev for now!
#endif
#include "src/common/libev/ev.h"
@@ -20,146 +20,165 @@ static int triton_aesocket_resource_id;
struct aesocket_op
{
- ae_op_id_t op_id;
- struct ae_op op;
- triton_ret_t tret;
- ev_io io;
+ ae_op_id_t op_id;
+ struct ae_op op;
+ triton_ret_t tret;
+ ev_io io;
};
static triton_mutex_t aesocket_mutex = TRITON_MUTEX_INITIALIZER;
-static void aesocket_fd_ready (EV_P_ ev_io * io, int revents)
+static void aesocket_fd_ready(
+ EV_P_ ev_io * io,
+ int revents)
{
- // mutex might be required here
- struct ae_op * op = (struct ae_op *) io->data;
- struct aesocket_op * socket_op =
- ae_op_entry(io->data, struct aesocket_op, op);
-
- struct ev_loop * eloop = ae_resource_get_eloop (op->ctx);
- ev_io_stop (eloop, io);
- ae_opcache_complete_op (aesocket_opcache, op, triton_ret_t, TRITON_SUCCESS);
- ae_resource_request_poll (op->ctx, triton_aesocket_resource_id);
+ // mutex might be required here
+ struct ae_op *op = (struct ae_op *) io->data;
+ struct aesocket_op *socket_op =
+ ae_op_entry(io->data, struct aesocket_op, op);
+
+ struct ev_loop *eloop = ae_resource_get_eloop(op->ctx);
+ ev_io_stop(eloop, io);
+ ae_opcache_complete_op(aesocket_opcache, op, triton_ret_t, TRITON_SUCCESS);
+ ae_resource_request_poll(op->ctx, triton_aesocket_resource_id);
}
-ae_define_post(triton_ret_t, triton_aesocket_ready, int fd, int mode)
+ae_define_post(triton_ret_t, triton_aesocket_ready, int fd,
+ int mode)
{
- struct ae_op * op;
- struct aesocket_op * socket_op;
+ struct ae_op *op;
+ struct aesocket_op *socket_op;
- if(!aesocket_opcache)
- {
- triton_err(triton_log_default, "Error: aesocket resource not initialized.");
- assert(0);
- }
+ if (!aesocket_opcache)
+ {
+ triton_err(triton_log_default,
+ "Error: aesocket resource not initialized.");
+ assert(0);
+ }
- op = ae_opcache_get(aesocket_opcache);
- ae_op_fill(op);
+ op = ae_opcache_get(aesocket_opcache);
+ ae_op_fill(op);
- socket_op = ae_op_entry(op, struct aesocket_op, op);
- socket_op->op_id = ae_id_gen(triton_aesocket_resource_id, (uint64_t)(op->cache_id));
- socket_op->tret = TRITON_SUCCESS;
+ socket_op = ae_op_entry(op, struct aesocket_op,
+ op);
+ socket_op->op_id =
+ ae_id_gen(triton_aesocket_resource_id, (uint64_t) (op->cache_id));
+ socket_op->tret = TRITON_SUCCESS;
- *__ae_op_id = socket_op->op_id;
+ *__ae_op_id = socket_op->op_id;
- int flags = (mode & AESOCKET_READ ? EV_READ : 0 )
- | (mode & AESOCKET_WRITE ? EV_WRITE : 0 );
+ int flags = (mode & AESOCKET_READ ? EV_READ : 0)
+ | (mode & AESOCKET_WRITE ? EV_WRITE : 0);
- assert (flags && "Need to specify one of AESOCKET_READ|AESOCKET_WRITE");
+ assert(flags && "Need to specify one of AESOCKET_READ|AESOCKET_WRITE");
- struct ev_loop * eloop = ae_resource_get_eloop (op->ctx);
+ struct ev_loop *eloop = ae_resource_get_eloop(op->ctx);
- ev_io_init (&socket_op->io, aesocket_fd_ready, fd, flags);
- socket_op->io.data = op;
+ ev_io_init(&socket_op->io, aesocket_fd_ready, fd, flags);
+ socket_op->io.data = op;
- // Is lock needed here? (to protect eloop?)
+ // Is lock needed here? (to protect eloop?)
- // how to prevent method from calling callback immediately? (or is this
- // OK)
- ev_io_start (eloop, &socket_op->io);
+ // how to prevent method from calling callback immediately? (or is this
+ // OK)
+ ev_io_start(eloop, &socket_op->io);
- return TRITON_SUCCESS;
+ return TRITON_SUCCESS;
}
-static triton_ret_t triton_aesocket_poll(ae_context_t context)
+static triton_ret_t triton_aesocket_poll(
+ ae_context_t context)
{
- return TRITON_SUCCESS;
+ return TRITON_SUCCESS;
}
-static triton_ret_t triton_aesocket_cancel(ae_context_t triton_ctx, ae_op_id_t op_id)
+static triton_ret_t triton_aesocket_cancel(
+ ae_context_t triton_ctx,
+ ae_op_id_t op_id)
{
- int cache_id, resource_id;
- struct ae_op * op;
- struct aesocket_op * socket_op;
- ae_context_t ctx;
+ int cache_id, resource_id;
+ struct ae_op *op;
+ struct aesocket_op *socket_op;
+ ae_context_t ctx;
- /* lock to keep the op from disappearing out from under us due to
- * completion
- */
- triton_mutex_lock(&aesocket_mutex);
+ /* lock to keep the op from disappearing out from under us due to
+ * completion
+ */
+ triton_mutex_lock(&aesocket_mutex);
- cache_id = ae_id_lookup(op_id, &resource_id);
- assert(resource_id == triton_aesocket_resource_id);
- op = ae_opcache_lookup(aesocket_opcache, (int)cache_id);
- socket_op = ae_op_entry(op, struct aesocket_op, op);
+ cache_id = ae_id_lookup(op_id, &resource_id);
+ assert(resource_id == triton_aesocket_resource_id);
+ op = ae_opcache_lookup(aesocket_opcache, (int) cache_id);
+ socket_op = ae_op_entry(op, struct aesocket_op,
+ op);
- //ae_ops_del(op);
+ //ae_ops_del(op);
- /* trigger callback immediately; no need to wait for a poll cycle */
- ctx = op->ctx;
+ /* trigger callback immediately; no need to wait for a poll cycle */
+ ctx = op->ctx;
- struct ev_loop * eloop = ae_resource_get_eloop (op->ctx);
- ev_io_stop (eloop, &socket_op->io);
+ struct ev_loop *eloop = ae_resource_get_eloop(op->ctx);
+ ev_io_stop(eloop, &socket_op->io);
- if (ev_is_pending (&socket_op->io))
- {
- // The operation is completed but callback was not called yet.
- ev_clear_pending (eloop, &socket_op->io);
- }
+ if (ev_is_pending(&socket_op->io))
+ {
+ // The operation is completed but callback was not called yet.
+ ev_clear_pending(eloop, &socket_op->io);
+ }
- triton_mutex_unlock(&aesocket_mutex);
+ triton_mutex_unlock(&aesocket_mutex);
- // calls callback and return op entry to the cache
- ae_opcache_complete_op(aesocket_opcache, op, triton_ret_t,
- TRITON_ERR_CANCELED);
+ // calls callback and return op entry to the cache
+ ae_opcache_complete_op(aesocket_opcache, op, triton_ret_t,
+ TRITON_ERR_CANCELED);
- ae_resource_request_poll(ctx, triton_aesocket_resource_id);
+ ae_resource_request_poll(ctx, triton_aesocket_resource_id);
- return TRITON_SUCCESS;
+ return TRITON_SUCCESS;
}
-struct ae_resource triton_aesocket_resource =
-{
- .resource_name = "aesocket",
- .poll_context = triton_aesocket_poll,
- .cancel = triton_aesocket_cancel
+struct ae_resource triton_aesocket_resource = {
+ .resource_name = "aesocket",
+ .poll_context = triton_aesocket_poll,
+ .cancel = triton_aesocket_cancel
};
-__attribute__((constructor)) void triton_aesocket_init_register(void);
+__attribute__ ((constructor))
+ void triton_aesocket_init_register(
+ void);
-__attribute__((constructor)) void triton_aesocket_init_register(void)
+__attribute__ ((constructor))
+ void triton_aesocket_init_register(
+ void)
{
triton_init_register("triton.resource.aesocket", triton_aesocket_init,
- triton_aesocket_finalize, NULL, "aesop.control");
+ triton_aesocket_finalize, NULL, "aesop.control");
}
-triton_ret_t triton_aesocket_init (void)
+triton_ret_t triton_aesocket_init(
+ void)
{
- triton_ret_t tret;
- int ret;
-
- tret = AE_OPCACHE_INIT (struct aesocket_op, op, AESOCKET_DEFAULT_SIZE, &aesocket_opcache);
- if (tret != TRITON_SUCCESS)
- {
- return tret;
- }
-
- return ae_resource_register (&triton_aesocket_resource, &triton_aesocket_resource_id);
+ triton_ret_t tret;
+ int ret;
+
+ tret = AE_OPCACHE_INIT(struct aesocket_op,
+ op,
+ AESOCKET_DEFAULT_SIZE,
+ &aesocket_opcache);
+ if (tret != TRITON_SUCCESS)
+ {
+ return tret;
+ }
+
+ return ae_resource_register(&triton_aesocket_resource,
+ &triton_aesocket_resource_id);
}
-void triton_aesocket_finalize (void)
+void triton_aesocket_finalize(
+ void)
{
- ae_resource_unregister(triton_aesocket_resource_id);
- ae_opcache_destroy(aesocket_opcache);
+ ae_resource_unregister(triton_aesocket_resource_id);
+ ae_opcache_destroy(aesocket_opcache);
}
/*
diff --git a/code/src/common/resources/aesocket/aesocket.hae b/code/src/common/resources/aesocket/aesocket.hae
index 4918f7f..a4d30cb 100644
--- a/code/src/common/resources/aesocket/aesocket.hae
+++ b/code/src/common/resources/aesocket/aesocket.hae
@@ -5,15 +5,27 @@
enum
{
- AESOCKET_READ = 0x01,
- AESOCKET_WRITE = 0x02
+ AESOCKET_READ = 0x01,
+ AESOCKET_WRITE = 0x02
};
-__blocking triton_ret_t triton_aesocket_ready (int fd, int mode);
+__blocking triton_ret_t triton_aesocket_ready(
+ int fd,
+ int mode);
-triton_ret_t triton_aesocket_init (void);
+triton_ret_t triton_aesocket_init(
+ void);
-void triton_aesocket_finalize (void);
+void triton_aesocket_finalize(
+ void);
#endif
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
diff --git a/code/src/socket/test/echo-server.ae b/code/src/socket/test/echo-server.ae
index 6ab95a9..fd9aa3f 100644
--- a/code/src/socket/test/echo-server.ae
+++ b/code/src/socket/test/echo-server.ae
@@ -15,118 +15,125 @@ int cb_ret;
#define LISTENPORT 9999
-static void done_callback(void *up, int ret)
+static void done_callback(
+ void *up,
+ int ret)
{
done = 1;
cb_ret = ret;
}
-static __blocking void handleConnection (int fd)
+static __blocking void handleConnection(
+ int fd)
{
- char buf[4096];
- triton_ret_t ret;
- int len;
- int written;
-
- printf ("New connection (fd %i)!\n", fd);
-
- /* mark socket as nonblocking */
- fcntl (fd, F_SETFL, O_NONBLOCK);
-
- pbranch
- {
-
- do
- {
- // @TODO: deal with short reads/connection closes?
- // maybe have the client first write the number of bytes it will
- // send?
- ret = triton_read (fd, &buf[0], sizeof(buf), &len);
- if (ret != TRITON_SUCCESS)
- {
- triton_error_print (ret, "error on read:");
- break;
- }
+ char buf[4096];
+ triton_ret_t ret;
+ int len;
+ int written;
- if (!len)
- break;
+ printf("New connection (fd %i)!\n", fd);
- printf ("Got data on fd %i: %i\n", fd, len);
+ /* mark socket as nonblocking */
+ fcntl(fd, F_SETFL, O_NONBLOCK);
- ret = triton_write (fd, &buf[0], len, &written);
- if (ret != TRITON_SUCCESS)
- {
- triton_error_print (ret, "error on write:");
- break;
- }
- printf ("Wrote data to fd %i: %i\n", fd, written);
- } while (1);
+ pbranch
+ {
- printf ("Client %i disconnect...\n", fd);
- close (fd);
- }
+ do
+ {
+ // @TODO: deal with short reads/connection closes?
+ // maybe have the client first write the number of bytes it will
+ // send?
+ ret = triton_read(fd, &buf[0], sizeof(buf), &len);
+ if (ret != TRITON_SUCCESS)
+ {
+ triton_error_print(ret, "error on read:");
+ break;
+ }
+
+ if (!len)
+ break;
+
+ printf("Got data on fd %i: %i\n", fd, len);
+
+ ret = triton_write(fd, &buf[0], len, &written);
+ if (ret != TRITON_SUCCESS)
+ {
+ triton_error_print(ret, "error on write:");
+ break;
+ }
+ printf("Wrote data to fd %i: %i\n", fd, written);
+ } while (1);
+
+ printf("Client %i disconnect...\n", fd);
+ close(fd);
+ }
}
-static __blocking int dotest ()
+static __blocking int dotest(
+ )
{
- int listensocket;
- struct sockaddr_in addr;
- triton_ret_t ret;
- int newsocket;
- int value = 1;
+ int listensocket;
+ struct sockaddr_in addr;
+ triton_ret_t ret;
+ int newsocket;
+ int value = 1;
- listensocket = socket (AF_INET, SOCK_STREAM, 0);
- if (listensocket < 0)
- {
- perror ("Error creating socket");
- return 0;
- }
+ listensocket = socket(AF_INET, SOCK_STREAM, 0);
+ if (listensocket < 0)
+ {
+ perror("Error creating socket");
+ return 0;
+ }
- fcntl (listensocket, F_SETFL, O_NONBLOCK);
+ fcntl(listensocket, F_SETFL, O_NONBLOCK);
- memset (&addr, 0, sizeof (addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- addr.sin_port = htons(LISTENPORT);
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ addr.sin_port = htons(LISTENPORT);
- /* allow address to be reused quickly */
- if(setsockopt(listensocket, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value)) < 0)
- {
- perror("setsockopt");
- }
+ /* allow address to be reused quickly */
+ if (setsockopt
+ (listensocket, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value)) < 0)
+ {
+ perror("setsockopt");
+ }
if (bind(listensocket, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
- perror ("Error binding listen socket");
- return 0;
+ perror("Error binding listen socket");
+ return 0;
}
- if (listen(listensocket, SOMAXCONN) < 0 )
+ if (listen(listensocket, SOMAXCONN) < 0)
{
- perror ("Error putting socket in listen state");
- return 0;
+ perror("Error putting socket in listen state");
+ return 0;
}
-
-
- while (1)
- {
- ret = triton_accept (listensocket, 0, 0, &newsocket);
- printf ("newsocket = %i\n", newsocket);
- if (ret != TRITON_SUCCESS)
- {
- perror ("error in accept");
- break;
- }
-
- handleConnection (newsocket);
- }
-
- return 0;
+
+
+ while (1)
+ {
+ ret = triton_accept(listensocket, 0, 0, &newsocket);
+ printf("newsocket = %i\n", newsocket);
+ if (ret != TRITON_SUCCESS)
+ {
+ perror("error in accept");
+ break;
+ }
+
+ handleConnection(newsocket);
+ }
+
+ return 0;
}
-int main (int argc, char ** args)
+int main(
+ int argc,
+ char **args)
{
triton_ret_t ret;
ae_context_t ctx;
@@ -134,16 +141,16 @@ int main (int argc, char ** args)
ae_op_id_t op_id;
triton_aesocket_init();
- triton_timer_init ();
+ triton_timer_init();
ae_context_create(&ctx, "timer", "aesocket");
ae_hints_init(&hints);
ret = ae_post_blocking(dotest, done_callback, NULL, &hints, ctx, &op_id,
- &cb_ret);
- if(ret == TRITON_SUCCESS)
+ &cb_ret);
+ if (ret == TRITON_SUCCESS)
{
- int pc = 0;
- while(!done)
+ int pc = 0;
+ while (!done)
{
ae_poll(ctx, 1000);
}
@@ -152,10 +159,17 @@ int main (int argc, char ** args)
ae_hints_destroy(&hints);
ae_context_destroy(ctx);
- triton_timer_finalize ();
+ triton_timer_finalize();
triton_aesocket_finalize();
return cb_ret;
}
-
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
diff --git a/code/src/socket/triton-socket.ae b/code/src/socket/triton-socket.ae
index 21789ac..8d5dfc1 100644
--- a/code/src/socket/triton-socket.ae
+++ b/code/src/socket/triton-socket.ae
@@ -5,89 +5,107 @@
#include <assert.h>
-__blocking triton_ret_t triton_accept (int sockfd, struct sockaddr * addr,
- socklen_t * addrlen, int * newfd)
+__blocking triton_ret_t triton_accept(
+ int sockfd,
+ struct sockaddr *addr,
+ socklen_t * addrlen,
+ int *newfd)
{
- triton_ret_t ret;
- int r;
+ triton_ret_t ret;
+ int r;
- *newfd = -1;
+ *newfd = -1;
- do
- {
- ret = triton_aesocket_ready (sockfd, AESOCKET_READ|AESOCKET_WRITE);
- if (ret != TRITON_SUCCESS)
- return ret;
+ do
+ {
+ ret = triton_aesocket_ready(sockfd, AESOCKET_READ | AESOCKET_WRITE);
+ if (ret != TRITON_SUCCESS)
+ return ret;
- r = accept (sockfd, addr, addrlen);
- if (r >= 0)
- break;
+ r = accept(sockfd, addr, addrlen);
+ if (r >= 0)
+ break;
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- continue;
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ continue;
- return triton_error_from_errno (errno);
+ return triton_error_from_errno(errno);
- } while (1);
+ } while (1);
- *newfd = r;
+ *newfd = r;
- printf ("newfd=%i\n", *newfd);
- return TRITON_SUCCESS;
+ printf("newfd=%i\n", *newfd);
+ return TRITON_SUCCESS;
}
-__blocking triton_ret_t triton_read (int fd, void * buf, size_t count, int * len)
+__blocking triton_ret_t triton_read(
+ int fd,
+ void *buf,
+ size_t count,
+ int *len)
{
- triton_ret_t ret;
- int r;
+ triton_ret_t ret;
+ int r;
- do
- {
- ret = triton_aesocket_ready (fd, AESOCKET_READ);
- if (ret != TRITON_SUCCESS)
- return ret;
+ do
+ {
+ ret = triton_aesocket_ready(fd, AESOCKET_READ);
+ if (ret != TRITON_SUCCESS)
+ return ret;
- r = read (fd, buf, count);
- *len = r;
+ r = read(fd, buf, count);
+ *len = r;
- if (r >= 0)
- break;
+ if (r >= 0)
+ break;
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- continue;
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ continue;
- return triton_error_from_errno (errno);
+ return triton_error_from_errno(errno);
- } while (1);
+ } while (1);
- return TRITON_SUCCESS;
+ return TRITON_SUCCESS;
}
-__blocking triton_ret_t triton_write (int fd, const void * buf, size_t count, int * len)
+__blocking triton_ret_t triton_write(
+ int fd,
+ const void *buf,
+ size_t count,
+ int *len)
{
- triton_ret_t ret;
- int r;
+ triton_ret_t ret;
+ int r;
- do
- {
- ret = triton_aesocket_ready (fd, AESOCKET_WRITE);
- if (ret != TRITON_SUCCESS)
- return ret;
+ do
+ {
+ ret = triton_aesocket_ready(fd, AESOCKET_WRITE);
+ if (ret != TRITON_SUCCESS)
+ return ret;
- r = write (fd, buf, count);
- *len = r;
+ r = write(fd, buf, count);
+ *len = r;
- if (r >= 0)
- break;
+ if (r >= 0)
+ break;
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- continue;
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ continue;
- return triton_error_from_errno (errno);
+ return triton_error_from_errno(errno);
- } while (1);
+ } while (1);
- return TRITON_SUCCESS;
+ return TRITON_SUCCESS;
}
-
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
diff --git a/code/src/socket/triton-socket.hae b/code/src/socket/triton-socket.hae
index 603a41f..e030f20 100644
--- a/code/src/socket/triton-socket.hae
+++ b/code/src/socket/triton-socket.hae
@@ -7,11 +7,31 @@
#include "src/aesop/aesop.h"
-__blocking triton_ret_t triton_accept (int sockfd, struct sockaddr * addr,
- socklen_t * addrlen, int * newfd);
+__blocking triton_ret_t triton_accept(
+ int sockfd,
+ struct sockaddr *addr,
+ socklen_t * addrlen,
+ int *newfd);
-__blocking triton_ret_t triton_read (int fd, void * buf, size_t count, int * ret);
+__blocking triton_ret_t triton_read(
+ int fd,
+ void *buf,
+ size_t count,
+ int *ret);
-__blocking triton_ret_t triton_write (int fd, const void * buf, size_t count, int * ret);
+__blocking triton_ret_t triton_write(
+ int fd,
+ const void *buf,
+ size_t count,
+ int *ret);
#endif
+
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
hooks/post-receive
--
Triton Repository