From 4ac5b0aa5e2dbda7232b923e0bb6b26cbf4cef5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20=C5=A0kr=C3=A1bal?= Date: Tue, 9 Nov 2004 10:39:06 +0000 Subject: [PATCH] - use edg_wll_Connection structure instead of using only socket descriptor --- org.glite.lb.client/Makefile | 6 ++++-- org.glite.lb.client/src/prod_proto.c | 12 ++++++------ org.glite.lb.client/src/prod_proto.h | 2 +- org.glite.lb.client/src/producer.c | 28 +++++++++++++++------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index ba64e6b..eaa21ee 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -91,8 +91,7 @@ PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la TOOLS:=dump load purge -#EXAMPLES:=feed_shark -EXAMPLES:= +EXAMPLES:=log_usertag_proxy job_reg feed_shark ${LIB}: ${LIBOBJS} ${LINK} -o $@ ${LIBLOBJS} -rpath ${glite_location}/lib -lglite_lb_common_${nothrflavour} @@ -142,8 +141,11 @@ ${LIBTHROBJS}: %.thr.o: %.c default: all + compile all: ${LIB} ${THRLIB} ${TOOLS} logevent ${EXAMPLES} ${PLUSLIB} ${THRPLUSLIB} +examples: ${EXAMPLES} + check: compile check.producer check.producer: producer_test diff --git a/org.glite.lb.client/src/prod_proto.c b/org.glite.lb.client/src/prod_proto.c index 109eb2c..5cfb889 100644 --- a/org.glite.lb.client/src/prod_proto.c +++ b/org.glite.lb.client/src/prod_proto.c @@ -165,7 +165,7 @@ int edg_wll_log_proto_client_failure(edg_wll_Context context, int code, edg_wll_ */ static int -get_reply(edg_wll_Context context, int sock, char **buf, int *code_min) +get_reply(edg_wll_Context context, edg_wll_Connection *conn, char **buf, int *code_min) { char buffer[17]; char *msg, *p; @@ -173,7 +173,7 @@ get_reply(edg_wll_Context context, int sock, char **buf, int *code_min) code = 0; /* get message header */ - len = edg_wll_plain_read_fullbuf(sock, buffer, 17, &context->p_tmp_timeout); + len = edg_wll_plain_read_full(conn, buffer, 17, &context->p_tmp_timeout); if(len < 0) { edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading message header"); goto get_reply_end; @@ -194,7 +194,7 @@ get_reply(edg_wll_Context context, int sock, char **buf, int *code_min) } /* read all the data */ - len = edg_wll_plain_read_fullbuf(sock, msg, len, &context->p_tmp_timeout); + len = edg_wll_plain_read_full(conn, msg, len, &context->p_tmp_timeout); if(len < 0) { edg_wll_SetError(context,LB_PROTO,"get_reply(): error reading message body"); goto get_reply_end; @@ -243,7 +243,7 @@ get_reply_end: * *---------------------------------------------------------------------- */ -int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_LogLine logline) +int edg_wll_log_proto_client_proxy(edg_wll_Context context, edg_wll_Connection *conn, edg_wll_LogLine logline) { char *p; int len; char *ucs = "honik6"; @@ -276,7 +276,7 @@ int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_ #ifdef EDG_WLL_LOG_STUB fprintf(stderr,"Sending message to socket...\n"); #endif - if (( count = edg_wll_plain_write_full(socket, buffer, size, &context->p_tmp_timeout)) < 0) { + if (( count = edg_wll_plain_write_full(conn, buffer, size, &context->p_tmp_timeout)) < 0) { edg_wll_SetError(context,LB_PROTO,"edg_wll_log_proto_client_proxy(): error sending message to socket"); goto edg_wll_log_proto_client_proxy_end; } @@ -286,7 +286,7 @@ int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_ fprintf(stderr,"Reading answer from server...\n"); #endif count = 0; - if ((err = get_reply(context, socket, &answer, &code)) < 0 ) { + if ((err = get_reply(context, conn, &answer, &code)) < 0 ) { edg_wll_SetError(context,LB_PROTO,"edg_wll_log_proto_client_proxy(): error reading answer from L&B proxy server"); } else { #ifdef EDG_WLL_LOG_STUB diff --git a/org.glite.lb.client/src/prod_proto.h b/org.glite.lb.client/src/prod_proto.h index c220594..c804256 100644 --- a/org.glite.lb.client/src/prod_proto.h +++ b/org.glite.lb.client/src/prod_proto.h @@ -20,7 +20,7 @@ extern "C" { int edg_wll_log_proto_client(edg_wll_Context context, edg_wll_GssConnection *con, edg_wll_LogLine logline/*, int priority,*/); int edg_wll_log_proto_client_failure(edg_wll_Context context, int code, edg_wll_GssStatus *gss_code, const char *text); -int edg_wll_log_proto_client_proxy(edg_wll_Context context, int socket, edg_wll_LogLine logline); +int edg_wll_log_proto_client_proxy(edg_wll_Context context, edg_wll_Connection *conn, edg_wll_LogLine logline); #ifdef __cplusplus } diff --git a/org.glite.lb.client/src/producer.c b/org.glite.lb.client/src/producer.c index c7885f3..de9602c 100644 --- a/org.glite.lb.client/src/producer.c +++ b/org.glite.lb.client/src/producer.c @@ -25,7 +25,7 @@ #include "prod_proto.h" -static const char* socket_path="/tmp/lbproxy.sock"; +static const char* socket_path="/tmp/lb_proxy_store.sock"; /** *---------------------------------------------------------------------- @@ -164,7 +164,8 @@ static int edg_wll_DoLogEventProxy( { int answer; struct sockaddr_un saddr; - int sock,flags; + int flags; + edg_wll_Connection conn; edg_wll_ResetError(context); answer = 0; @@ -172,25 +173,27 @@ static int edg_wll_DoLogEventProxy( /* open a connection to the L&B Proxy: */ #ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"Logging to L&B Proxy at socket %s\n", socketpath); + fprintf(stderr,"Logging to L&B Proxy at socket %s\n", + context->p_lbproxy_store_sock? context->p_lbproxy_store_sock: socket_path); #endif - sock = socket(PF_UNIX, SOCK_STREAM, 0); - if (sock < 0) { + conn.sock = socket(PF_UNIX, SOCK_STREAM, 0); + if (conn.sock < 0) { edg_wll_SetError(context,answer = errno,"socket() error"); goto edg_wll_DoLogEventProxy_end; } memset(&saddr, 0, sizeof(saddr)); saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, socket_path); - if ((flags = fcntl(sock, F_GETFL, 0)) < 0 || fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) { + strcpy(saddr.sun_path, context->p_lbproxy_store_sock? + context->p_lbproxy_store_sock: socket_path); + if ((flags = fcntl(conn.sock, F_GETFL, 0)) < 0 || fcntl(conn.sock, F_SETFL, flags | O_NONBLOCK) < 0) { edg_wll_SetError(context,answer = errno,"fcntl()"); - close(sock); + close(conn.sock); goto edg_wll_DoLogEventProxy_end; } - if (connect(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { + if (connect(conn.sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { if(errno != EISCONN) { edg_wll_SetError(context,answer = errno,"connect()"); - close(sock); + close(conn.sock); goto edg_wll_DoLogEventProxy_end; } } @@ -198,10 +201,9 @@ static int edg_wll_DoLogEventProxy( /* and send the message to the L&B Proxy: */ -// answer = edg_wll_log_proto_client_proxy(context,&sock,logline); - answer = EAGAIN; + answer = edg_wll_log_proto_client_proxy(context,&conn,logline); - close(sock); + close(conn.sock); edg_wll_DoLogEventProxy_end: -- 1.8.2.3