Triton Repository branch, master, updated. 341b8154fa409182bc1028197598fa8dd906c0cf
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 341b8154fa409182bc1028197598fa8dd906c0cf (commit) via 7115fbd9cd2b8946884d2ba1d3b40e75310c53f9 (commit) from 0afd4c3842dcf99471d93e0d65aee77f4f731181 (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 341b8154fa409182bc1028197598fa8dd906c0cf Author: Phil Carns <[email protected]> Date: Tue Jun 14 23:24:04 2011 -0400 switch to main_set macro commit 7115fbd9cd2b8946884d2ba1d3b40e75310c53f9 Author: Phil Carns <[email protected]> Date: Tue Jun 14 22:53:22 2011 -0400 strip echo-server code for complexity analysis ----------------------------------------------------------------------- Summary of changes: code/src/common/triton-init.c | 8 + code/src/socket/test/echo-server.ae | 286 +++++++++-------------------------- 2 files changed, 82 insertions(+), 212 deletions(-) Diff of changes: diff --git a/code/src/common/triton-init.c b/code/src/common/triton-init.c index 7804be7..7aa0d12 100644 --- a/code/src/common/triton-init.c +++ b/code/src/common/triton-init.c @@ -412,6 +412,14 @@ __attribute__((constructor)) void triton_logical_register(void) "triton.vosd.file", "triton.vosd"); + triton_init_register("triton.echo-server", + NULL, + NULL, + NULL, + "triton.vosd.file", + "triton.resource.timer", + "triton.resource.aesocket"); + triton_init_register("triton.server", NULL, NULL, diff --git a/code/src/socket/test/echo-server.ae b/code/src/socket/test/echo-server.ae index fee2a08..a7564a5 100644 --- a/code/src/socket/test/echo-server.ae +++ b/code/src/socket/test/echo-server.ae @@ -14,17 +14,26 @@ #include <signal.h> #include <netinet/tcp.h> -int done = 0; -int cb_ret; - #define LISTENPORT 9999 -static void done_callback( - void *up, - int ret) +static void handler(int sig) { - done = 1; - cb_ret = ret; + FILE* status; + char buf[128]; + + status = fopen("/proc/self/status", "r"); + if(status) + { + while(fgets(buf, 128, status)) + { + if(strncmp(buf, "VmPeak", strlen("VmPeak")) == 0) + { + printf("%s", buf); + break; + } + } + } + exit(0); } static __blocking void handleConnection( @@ -36,32 +45,25 @@ static __blocking void handleConnection( int written; struct test_request req; struct test_response resp; - int end_loop = 0; int file_fd; - int error_code; resp.error_code = 42; - // printf("New connection (fd %i)!\n", fd); - /* mark socket as nonblocking */ fcntl(fd, F_SETFL, O_NONBLOCK); pbranch { - do + while(1) { /* read request */ ret = triton_read(fd, &req, sizeof(req), &len); if (ret != TRITON_SUCCESS) { - // printf("Socket error or socket closed.\n"); + /* connection closed */ break; } - assert(len == sizeof(req)); - - // printf("Got request on fd %i\n", fd); /* allocate a buffer for moving data */ buffer = malloc(req.size); @@ -71,142 +73,76 @@ static __blocking void handleConnection( switch(req.type) { case TEST_READ_NULL: -// printf("read_null request\n"); ret = triton_write(fd, &resp, sizeof(resp), &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(written == sizeof(resp)); + assert(ret == TRITON_SUCCESS); ret = triton_write(fd, buffer, req.size, &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(written == req.size); - // printf("Serviced a READ_NULL request.\n"); + assert(ret == TRITON_SUCCESS); break; + case TEST_WRITE_NULL: ret = triton_read(fd, buffer, req.size, &len); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(len == req.size); + assert(ret == TRITON_SUCCESS); ret = triton_write(fd, &resp, sizeof(resp), &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(written == sizeof(resp)); + assert(ret == TRITON_SUCCESS); break; + case TEST_READ: ret = file_open(&file_fd, req.filename, (O_RDONLY), 0644); - if (ret == TRITON_SUCCESS) - { - ret = file_pread(file_fd, - buffer, - req.size, - 0); - if (ret == TRITON_SUCCESS) - { - ret = triton_write(fd, buffer, req.size, &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on triton_write"); - } - assert(written == req.size); - } - else - { - triton_error_print(ret, "error on file_pread"); - } - ret = file_close(file_fd); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on file_close"); - } - } - else - { - triton_error_print(ret, "error on file_open"); - break; - } + assert(ret == TRITON_SUCCESS); + + ret = file_pread(file_fd, + buffer, + req.size, + 0); + assert(ret == TRITON_SUCCESS); + + ret = triton_write(fd, buffer, req.size, &written); + assert(ret == TRITON_SUCCESS); + + ret = file_close(file_fd); + assert(ret == TRITON_SUCCESS); + ret = triton_write(fd, &resp, sizeof(resp), &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(written == sizeof(resp)); + assert(ret == TRITON_SUCCESS); break; + case TEST_WRITE: ret = triton_read(fd, buffer, req.size, &len); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(len == req.size); + assert(ret == TRITON_SUCCESS); + ret = file_open(&file_fd, req.filename, (O_CREAT|O_TRUNC|O_WRONLY), 0644); - if (ret == TRITON_SUCCESS) - { - ret = file_pwrite(file_fd, - buffer, - req.size, - 0); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on file_pwrite"); - } - ret = file_close(file_fd); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on file_close"); - } - } - else - { - triton_error_print(ret, "error on file_open"); - } + assert(ret == TRITON_SUCCESS); + + ret = file_pwrite(file_fd, + buffer, + req.size, + 0); + assert(ret == TRITON_SUCCESS); + + ret = file_close(file_fd); + assert(ret == TRITON_SUCCESS); + ret = triton_write(fd, &resp, sizeof(resp), &written); - if (ret != TRITON_SUCCESS) - { - triton_error_print(ret, "error on write:"); - end_loop = 1; - break; - } - assert(written == sizeof(resp)); + assert(ret == TRITON_SUCCESS); break; + default: assert(0); } free(buffer); - } while (!end_loop); + }; - //printf("Client %i disconnect...\n", fd); close(fd); } } -static __blocking int dotest( - ) +static __blocking int dotest(int argc, char** argv) { int listensocket; struct sockaddr_in addr; @@ -215,13 +151,16 @@ static __blocking int dotest( int value = 1; int rc; + struct sigaction new_action; + new_action.sa_handler = handler; + sigemptyset(&new_action.sa_mask); + new_action.sa_flags = SA_RESETHAND; + sigaction(SIGTERM, &new_action, NULL); + sigaction(SIGINT, &new_action, NULL); + sigaction(SIGQUIT, &new_action, NULL); listensocket = socket(AF_INET, SOCK_STREAM, 0); - if (listensocket < 0) - { - perror("Error creating socket"); - return 0; - } + assert(listensocket >= 0); fcntl(listensocket, F_SETFL, O_NONBLOCK); @@ -231,34 +170,19 @@ static __blocking int dotest( addr.sin_port = htons(LISTENPORT); /* 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; - } + rc = setsockopt(listensocket, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value)); + assert(rc == 0); - if (listen(listensocket, SOMAXCONN) < 0) - { - perror("Error putting socket in listen state"); - return 0; - } + rc = bind(listensocket, (struct sockaddr *) &addr, sizeof(addr)); + assert(rc == 0); + rc = listen(listensocket, SOMAXCONN); + assert(rc == 0); while (1) { ret = triton_accept(listensocket, 0, 0, &newsocket); - //printf("newsocket = %i\n", newsocket); - if (ret != TRITON_SUCCESS) - { - perror("error in accept"); - break; - } + assert(ret == TRITON_SUCCESS); rc = setsockopt(newsocket, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); @@ -270,69 +194,7 @@ static __blocking int dotest( return 0; } -static void handler(int sig) -{ - FILE* status; - char buf[128]; - - status = fopen("/proc/self/status", "r"); - if(status) - { - while(fgets(buf, 128, status)) - { - if(strncmp(buf, "VmPeak", strlen("VmPeak")) == 0) - { - printf("%s", buf); - break; - } - } - } - exit(0); -} - -int main( - int argc, - char **args) -{ - triton_ret_t ret; - ae_context_t ctx; - ae_hints_t hints; - ae_op_id_t op_id; - - struct sigaction new_action; - new_action.sa_handler = handler; - sigemptyset(&new_action.sa_mask); - new_action.sa_flags = SA_RESETHAND; - sigaction(SIGTERM, &new_action, NULL); - sigaction(SIGINT, &new_action, NULL); - sigaction(SIGQUIT, &new_action, NULL); - - triton_init("triton.vosd.file", - "triton.resource.timer", - "triton.resource.aesocket"); - - ae_context_create(&ctx, "timer", "aesocket", "file"); - - ae_hints_init(&hints); - ret = ae_post_blocking(dotest, done_callback, NULL, &hints, ctx, &op_id, - &cb_ret); - if (ret == TRITON_SUCCESS) - { - int pc = 0; - while (!done) - { - ae_poll(ctx, 1000); - } - } - triton_error_assert(ret); - - ae_hints_destroy(&hints); - ae_context_destroy(ctx); - - triton_finalize(); - - return cb_ret; -} +aesop_main_set_with_init(NULL, "triton.echo-server", dotest, "timer", "aesocket", "file"); /* * Local variables: hooks/post-receive -- Triton Repository
participants (1)
-
noreply@mcs.anl.gov