From 262562715930f4fbc424ca85da6aeac20e204135 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20=C5=A0kr=C3=A1bal?= Date: Wed, 8 Dec 2004 11:36:21 +0000 Subject: [PATCH] - plain_io defines its own type for communication (rolling back some recent changes which cased the inconsistency) - changes in context - using right data for buffers and for comunication --- org.glite.lb.common/interface/context-int.h | 19 ++++---- org.glite.lb.common/interface/lb_plain_io.h | 19 +++++--- org.glite.lb.common/project/version.properties | 4 +- org.glite.lb.common/src/context.c | 11 +++-- org.glite.lb.common/src/lb_plain_io.c | 48 ++++++++++--------- org.glite.lb.common/src/mini_http.c | 65 +++++++++++++------------- 6 files changed, 89 insertions(+), 77 deletions(-) diff --git a/org.glite.lb.common/interface/context-int.h b/org.glite.lb.common/interface/context-int.h index 0a28db5..0852e33 100644 --- a/org.glite.lb.common/interface/context-int.h +++ b/org.glite.lb.common/interface/context-int.h @@ -5,7 +5,7 @@ #include "glite/lb/consumer.h" #include "lb_gss.h" -//#include "lb_plain_io.h" +#include "lb_plain_io.h" #include "authz.h" #ifdef __cplusplus @@ -18,13 +18,13 @@ typedef struct _edg_wll_SeqCode { -/* non-gsi one-element analogy of connPool */ -typedef struct _edg_wll_Connection { - int sock; - char *buf; - size_t bufSize; - size_t bufUse; -} edg_wll_Connection; +/* non-gsi one-element analogy of connPool for L&B Proxy server */ +typedef struct _edg_wll_ConnProxy { + edg_wll_PlainConnection conn; + char *buf; + size_t bufSize; + size_t bufUse; +} edg_wll_ConnProxy; @@ -55,8 +55,7 @@ struct _edg_wll_Context { void *mysql; edg_wll_ConnPool *connPool; edg_wll_ConnPool *connPoolNotif; /* hold _one_ connection from notif-interlogger */ - - edg_wll_Connection *connPlain; /* holds one plain connection */ + edg_wll_ConnProxy *connProxy; /* holds one plain connection */ int semaphores,semset; edg_wll_QueryRec **job_index; diff --git a/org.glite.lb.common/interface/lb_plain_io.h b/org.glite.lb.common/interface/lb_plain_io.h index 29c5032..d423bbc 100644 --- a/org.glite.lb.common/interface/lb_plain_io.h +++ b/org.glite.lb.common/interface/lb_plain_io.h @@ -2,32 +2,39 @@ #define __EDG_WORKLOAD_LOGGING_COMMON_LB_PLAIN_IO_H__ -#include "context-int.h" - #ifdef __cplusplus extern "C" { #endif +typedef struct _edg_wll_PlainConnection { + int sock; + char *buf; + size_t bufSize; + size_t bufUse; +} edg_wll_PlainConnection; int edg_wll_plain_accept( int sock, - edg_wll_Connection *conn); + edg_wll_PlainConnection *conn); + +int edg_wll_plain_close( + edg_wll_PlainConnection *conn); int edg_wll_plain_read( - edg_wll_Connection *conn, + edg_wll_PlainConnection *conn, void *outbuf, size_t outbufsz, struct timeval *timeout); int edg_wll_plain_read_full( - edg_wll_Connection *conn, + edg_wll_PlainConnection *conn, void *outbuf, size_t outbufsz, struct timeval *timeout); int edg_wll_plain_write_full( - edg_wll_Connection *conn, + edg_wll_PlainConnection *conn, const void *buf, size_t bufsz, struct timeval *timeout); diff --git a/org.glite.lb.common/project/version.properties b/org.glite.lb.common/project/version.properties index ec4230f..c400a5e 100644 --- a/org.glite.lb.common/project/version.properties +++ b/org.glite.lb.common/project/version.properties @@ -1,4 +1,4 @@ -#Wed Dec 08 05:57:58 CET 2004 -module.version=0.4.1 +#Wed Dec 08 06:05:04 CET 2004 +module.version=1.4.1 module.build=109 module.age=2 diff --git a/org.glite.lb.common/src/context.c b/org.glite.lb.common/src/context.c index 73d5372..e58270f 100644 --- a/org.glite.lb.common/src/context.c +++ b/org.glite.lb.common/src/context.c @@ -32,7 +32,8 @@ int edg_wll_InitContext(edg_wll_Context *ctx) out->connPool = (edg_wll_ConnPool *) calloc(out->poolSize, sizeof(edg_wll_ConnPool)); out->connPoolNotif = (edg_wll_ConnPool *) calloc(1, sizeof(edg_wll_ConnPool)); - out->connPlain = (edg_wll_Connection *) calloc(1, sizeof(edg_wll_Connection)); + out->connProxy = (edg_wll_ConnPool *) calloc(1, sizeof(edg_wll_ConnProxy)); + out->connProxy->conn.sock = -1; *ctx = out; return 0; @@ -58,10 +59,10 @@ void edg_wll_FreeContext(edg_wll_Context ctx) } free(ctx->connPool); } - if ( ctx->connPlain ) { - if ( ctx->connPlain->buf ) free(ctx->connPlain->buf); - close(ctx->connPlain->sock); - free(ctx->connPlain); + if ( ctx->connProxy ) { + if ( ctx->connProxy->buf ) free(ctx->connProxy->buf); + edg_wll_plain_close(&ctx->connProxy->conn); + free(ctx->connProxy); } if (ctx->notifSock >=0) close(ctx->notifSock); if (ctx->srvName) free(ctx->srvName); diff --git a/org.glite.lb.common/src/lb_plain_io.c b/org.glite.lb.common/src/lb_plain_io.c index d105ec2..f197c9b 100644 --- a/org.glite.lb.common/src/lb_plain_io.c +++ b/org.glite.lb.common/src/lb_plain_io.c @@ -29,34 +29,38 @@ } int edg_wll_plain_connect( - char const *hostname, - int port, - struct timeval *to, - edg_wll_Connection *conn) + char const *hostname, + int port, + struct timeval *to, + edg_wll_PlainConnection *conn) { return 0; } int edg_wll_plain_accept( - int sock, - edg_wll_Connection *conn) + int sock, + edg_wll_PlainConnection *conn) { - struct sockaddr_in a; - int alen = sizeof(a); - /* Do not free the buffer here - just reuse the memmory */ conn->bufUse = 0; - /* - if ( (conn->sock = accept(sock, (struct sockaddr *)&a, &alen)) ) - return -1; - */ conn->sock = sock; return 0; } +int edg_wll_plain_close(edg_wll_PlainConnection *conn) +{ + errno = 0; + if ( conn->buf ) free(conn->buf); + if ( conn->sock > -1 ) close(conn->sock); + memset(conn, 0, sizeof(*conn)); + conn->sock = -1; + + return errno? -1: 0; +} + int edg_wll_plain_read( - edg_wll_Connection *conn, + edg_wll_PlainConnection *conn, void *outbuf, size_t outbufsz, struct timeval *to) @@ -134,10 +138,10 @@ cleanup: int edg_wll_plain_read_full( - edg_wll_Connection *conn, - void *outbuf, - size_t outbufsz, - struct timeval *to) + edg_wll_PlainConnection *conn, + void *outbuf, + size_t outbufsz, + struct timeval *to) { size_t total = 0; @@ -160,10 +164,10 @@ int edg_wll_plain_read_full( } int edg_wll_plain_write_full( - edg_wll_Connection *conn, - const void *buf, - size_t bufsz, - struct timeval *to) + edg_wll_PlainConnection *conn, + const void *buf, + size_t bufsz, + struct timeval *to) { size_t written = 0; int ct = -1; diff --git a/org.glite.lb.common/src/mini_http.c b/org.glite.lb.common/src/mini_http.c index 87f71d4..7e86628 100644 --- a/org.glite.lb.common/src/mini_http.c +++ b/org.glite.lb.common/src/mini_http.c @@ -154,49 +154,50 @@ edg_wll_ErrorCode edg_wll_http_recv_proxy(edg_wll_Context ctx,char **firstOut,ch int len, nhdr = 0,rdmore = 0,clen = 0,blen = 0; #define bshift(shift) {\ - memmove(ctx->connPlain->buf,\ - ctx->connPlain->buf+(shift),\ - ctx->connPlain->bufUse-(shift));\ - ctx->connPlain->bufUse -= (shift);\ + memmove(ctx->connProxy->buf,\ + ctx->connProxy->buf+(shift),\ + ctx->connProxy->bufUse-(shift));\ + ctx->connProxy->bufUse -= (shift);\ } edg_wll_ResetError(ctx); - if ( !ctx->connPlain->buf ) { - ctx->connPlain->bufSize = BUFSIZ; - ctx->connPlain->buf = malloc(BUFSIZ); + if ( !ctx->connProxy->buf ) { + ctx->connProxy->bufSize = BUFSIZ; + ctx->connProxy->bufUse = 0; + ctx->connProxy->buf = malloc(BUFSIZ); } do { - len = edg_wll_plain_read(ctx->connPlain, - ctx->connPlain->buf+ctx->connPlain->bufUse, - ctx->connPlain->bufSize-ctx->connPlain->bufUse, + len = edg_wll_plain_read(&ctx->connProxy->conn, + ctx->connProxy->buf+ctx->connProxy->bufUse, + ctx->connProxy->bufSize-ctx->connProxy->bufUse, &ctx->p_tmp_timeout); if ( len < 0 ) { edg_wll_SetError(ctx, errno, "edg_wll_plain_read()"); goto error; } - ctx->connPlain->bufUse += len; + ctx->connProxy->bufUse += len; rdmore = 0; while (!rdmore && pstat != DONE) switch (pstat) { char *cr; case FIRST: - if ((cr = memchr(ctx->connPlain->buf,'\r',ctx->connPlain->bufUse)) && - ctx->connPlain->bufUse >= cr-ctx->connPlain->buf+2 && cr[1] == '\n') + if ((cr = memchr(ctx->connProxy->buf,'\r',ctx->connProxy->bufUse)) && + ctx->connProxy->bufUse >= cr-ctx->connProxy->buf+2 && cr[1] == '\n') { *cr = 0; - first = strdup(ctx->connPlain->buf); - bshift(cr-ctx->connPlain->buf+2); + first = strdup(ctx->connProxy->buf); + bshift(cr-ctx->connProxy->buf+2); pstat = HEAD; } else rdmore = 1; break; case HEAD: - if ((cr = memchr(ctx->connPlain->buf,'\r',ctx->connPlain->bufUse)) && - ctx->connPlain->bufUse >= cr-ctx->connPlain->buf+2 && cr[1] == '\n') + if ((cr = memchr(ctx->connProxy->buf,'\r',ctx->connProxy->bufUse)) && + ctx->connProxy->bufUse >= cr-ctx->connProxy->buf+2 && cr[1] == '\n') { - if (cr == ctx->connPlain->buf) { + if (cr == ctx->connProxy->buf) { bshift(2); pstat = clen ? BODY : DONE; if (clen) body = malloc(clen+1); @@ -205,19 +206,19 @@ edg_wll_ErrorCode edg_wll_http_recv_proxy(edg_wll_Context ctx,char **firstOut,ch *cr = 0; hdr = realloc(hdr,(nhdr+2) * sizeof(*hdr)); - hdr[nhdr] = strdup(ctx->connPlain->buf); + hdr[nhdr] = strdup(ctx->connProxy->buf); hdr[++nhdr] = NULL; - if (!strncasecmp(ctx->connPlain->buf,CONTENT_LENGTH,sizeof(CONTENT_LENGTH)-1)) - clen = atoi(ctx->connPlain->buf+sizeof(CONTENT_LENGTH)-1); + if (!strncasecmp(ctx->connProxy->buf,CONTENT_LENGTH,sizeof(CONTENT_LENGTH)-1)) + clen = atoi(ctx->connProxy->buf+sizeof(CONTENT_LENGTH)-1); - bshift(cr-ctx->connPlain->buf+2); + bshift(cr-ctx->connProxy->buf+2); } else rdmore = 1; break; case BODY: - if (ctx->connPlain->bufUse) { - int m = min(ctx->connPlain->bufUse,clen-blen); - memcpy(body+blen,ctx->connPlain->buf,m); + if (ctx->connProxy->bufUse) { + int m = min(ctx->connProxy->bufUse,clen-blen); + memcpy(body+blen,ctx->connProxy->buf,m); blen += m; bshift(m); } @@ -338,16 +339,16 @@ edg_wll_ErrorCode edg_wll_http_send_proxy(edg_wll_Context ctx, const char *first edg_wll_ResetError(ctx); - if ( edg_wll_plain_write_full(ctx->connPlain, + if ( edg_wll_plain_write_full(&ctx->connProxy->conn, first, strlen(first), &ctx->p_tmp_timeout) < 0 - || edg_wll_plain_write_full(ctx->connPlain, + || edg_wll_plain_write_full(&ctx->connProxy->conn, "\r\n", 2, &ctx->p_tmp_timeout) < 0 ) return edg_wll_SetError(ctx, errno, "edg_wll_http_send()"); if ( head ) for ( h = head; *h; h++ ) - if ( edg_wll_plain_write_full(ctx->connPlain, + if ( edg_wll_plain_write_full(&ctx->connProxy->conn, *h, strlen(*h), &ctx->p_tmp_timeout) < 0 - || edg_wll_plain_write_full(ctx->connPlain, + || edg_wll_plain_write_full(&ctx->connProxy->conn, "\r\n", 2, &ctx->p_tmp_timeout) < 0 ) return edg_wll_SetError(ctx, errno, "edg_wll_http_send()"); @@ -356,15 +357,15 @@ edg_wll_ErrorCode edg_wll_http_send_proxy(edg_wll_Context ctx, const char *first len = strlen(body); blen = sprintf(buf, CONTENT_LENGTH " %d\r\n",len); - if (edg_wll_plain_write_full(ctx->connPlain, + if (edg_wll_plain_write_full(&ctx->connProxy->conn, buf, blen, &ctx->p_tmp_timeout) < 0) return edg_wll_SetError(ctx, errno, "edg_wll_http_send()"); } - if ( edg_wll_plain_write_full(ctx->connPlain, + if ( edg_wll_plain_write_full(&ctx->connProxy->conn, "\r\n", 2, &ctx->p_tmp_timeout) < 0) return edg_wll_SetError(ctx, errno, "edg_wll_http_send()"); - if ( body && edg_wll_plain_write_full(ctx->connPlain, + if ( body && edg_wll_plain_write_full(&ctx->connProxy->conn, body, len, &ctx->p_tmp_timeout) < 0) return edg_wll_SetError(ctx, errno, "edg_wll_http_send()"); -- 1.8.2.3