changeset 710:e60376cb15e8

Minor changes
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 10 Feb 2011 16:00:53 +0900
parents 19a9470de77a
children f7c665948e0c
files libfdcore/cnxctx.c libfdcore/sctp.c libfdproto/fdproto-internal.h libfdproto/messages.c libfdproto/msg_log.c
diffstat 5 files changed, 46 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libfdcore/cnxctx.c	Thu Feb 10 10:49:09 2011 +0900
+++ b/libfdcore/cnxctx.c	Thu Feb 10 16:00:53 2011 +0900
@@ -621,8 +621,9 @@
 	int timedout = 0;
 again:
 	ret = recv(conn->cc_socket, buffer, length, 0);
-	/* Handle special case of timeout */
-	if ((ret < 0) && (errno == EAGAIN)) {
+	/* Handle special case of timeout / interrupts */
+	if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
+		pthread_testcancel();
 		if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING ))
 			goto again; /* don't care, just ignore */
 		if (!timedout) {
@@ -648,7 +649,8 @@
 again:
 	ret = send(conn->cc_socket, buffer, length, 0);
 	/* Handle special case of timeout */
-	if ((ret < 0) && (errno == EAGAIN)) {
+	if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
+		pthread_testcancel();
 		if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING ))
 			goto again; /* don't care, just ignore */
 		if (!timedout) {
--- a/libfdcore/sctp.c	Thu Feb 10 10:49:09 2011 +0900
+++ b/libfdcore/sctp.c	Thu Feb 10 16:00:53 2011 +0900
@@ -1040,7 +1040,8 @@
 again:	
 	ret = sendmsg(conn->cc_socket, &mhdr, 0);
 	/* Handle special case of timeout */
-	if ((ret < 0) && (errno == EAGAIN)) {
+	if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
+		pthread_testcancel();
 		if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING ))
 			goto again; /* don't care, just ignore */
 		if (!timedout) {
@@ -1098,10 +1099,11 @@
 again:
 	pthread_cleanup_push(free, data);
 	ret = recvmsg(conn->cc_socket, &mhdr, 0);
+	pthread_testcancel();
 	pthread_cleanup_pop(0);
 	
 	/* First, handle timeouts (same as fd_cnx_s_recv) */
-	if ((ret < 0) && (errno == EAGAIN)) {
+	if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
 		if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING ))
 			goto again; /* don't care, just ignore */
 		if (!timedout) {
--- a/libfdproto/fdproto-internal.h	Thu Feb 10 10:49:09 2011 +0900
+++ b/libfdproto/fdproto-internal.h	Thu Feb 10 16:00:53 2011 +0900
@@ -51,6 +51,7 @@
 FILE * fd_g_debug_fstr;
 
 /* Special message dump function */
+void fd_msg_dump_fstr_one ( struct msg * msg, FILE * fstr );
 void fd_msg_dump_fstr ( struct msg * msg, FILE * fstr );
 
 /* Iterator on the rules of a parent object */
--- a/libfdproto/messages.c	Thu Feb 10 10:49:09 2011 +0900
+++ b/libfdproto/messages.c	Thu Feb 10 16:00:53 2011 +0900
@@ -807,6 +807,10 @@
 		/* dump next object */
 	} while (ref);
 }
+void fd_msg_dump_fstr_one ( struct msg * msg, FILE * fstr ) /* just the header */
+{
+	msg_dump_intern ( NONE, msg, 2, fstr );
+}
 
 /* Dump a message content -- for debug mostly */
 void fd_msg_dump_walk ( int level, msg_or_avp *obj )
--- a/libfdproto/msg_log.c	Thu Feb 10 10:49:09 2011 +0900
+++ b/libfdproto/msg_log.c	Thu Feb 10 16:00:53 2011 +0900
@@ -108,6 +108,11 @@
 	const char * 		metharg;
 	FILE * fstr;
 	
+	char buftime[256];
+	size_t offset = 0;
+	struct timespec ts;
+	struct tm tm;
+	
 	TRACE_ENTRY("%d %p %p", cause, msg, prefix_format);
 	CHECK_PARAMS_DO( (cause >= 0) && (cause <= FD_MSG_LOG_MAX),
 	{
@@ -124,6 +129,12 @@
 	metharg = ml_conf.causes[cause].metharg;
 	CHECK_POSIX_DO( pthread_mutex_unlock(&ml_conf.lock), );
 	
+	/* Get current time */
+	CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), /* continue */);
+	offset += strftime(buftime + offset, sizeof(buftime) - offset, "%D,%T", localtime_r( &ts.tv_sec , &tm ));
+	offset += snprintf(buftime + offset, sizeof(buftime) - offset, ".%6.6ld", ts.tv_nsec / 1000);
+	
+
 	/* Okay, now we will create the file descriptor */
 	switch (meth) {
 		case FD_MSG_LOGTO_DEBUGONLY:
@@ -141,7 +152,7 @@
 	}
 	
 	/* For file methods, let's parse the message so it looks better */
-	if ((meth != FD_MSG_LOGTO_DEBUGONLY) && ml_conf.dict) {
+	if (((meth != FD_MSG_LOGTO_DEBUGONLY) || (fd_g_debug_lvl > FULL)) && ml_conf.dict) {
 		CHECK_FCT_DO( fd_msg_parse_dict( msg, ml_conf.dict, NULL ), );
 	}
 	
@@ -154,12 +165,29 @@
 	fflush(fstr);
 	pthread_cleanup_pop(0);
 	(void)pthread_mutex_unlock(&fd_log_lock);
-	fd_log_debug_fstr(fstr, "\n\n");
+	
+	fd_log_debug_fstr(fstr, "\nLogged: %s\n\n", buftime);
 	
 	/* And now the message itself */
-	fd_msg_dump_fstr(msg, fstr);
+	if ((meth == FD_MSG_LOGTO_DEBUGONLY) && (fd_g_debug_lvl <= INFO)) {
+		/* dump only the header */
+		fd_msg_dump_fstr_one(msg, fstr);
+	} else {
+		/* dump the full content */
+		fd_msg_dump_fstr(msg, fstr);
+	}
 	
 	/* And finally close the stream if needed */
-	TODO("close?");
+	switch (meth) {
+		case FD_MSG_LOGTO_DEBUGONLY:
+			break;
+			
+		case FD_MSG_LOGTO_FILE:
+			TODO("close?");
+			break;
+		case FD_MSG_LOGTO_DIR:
+			TODO("close?");
+			break;
+	}
 }
 
"Welcome to our mercurial repository"