changeset 939:1bc052ef961f

Add a function to access this counter
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 12 Mar 2013 15:27:59 +0100
parents 4158151cc694
children 9b00b868e308
files include/freeDiameter/libfdcore.h libfdcore/peers.c
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdcore.h	Tue Mar 12 15:27:30 2013 +0100
+++ b/include/freeDiameter/libfdcore.h	Tue Mar 12 15:27:59 2013 +0100
@@ -384,6 +384,23 @@
  */
 int fd_peer_get_state(struct peer_hdr *peer);
 
+/* 
+ * FUNCTION:	fd_peer_get_load_pending
+ *
+ * PARAMETERS:
+ *  peer	: The peer which load to read
+ *
+ * DESCRIPTION: 
+ *   Returns the current number of requests sent to this peer
+ *  that have not been answered yet. This is an empirical indication
+ *  of the workload of this peer.
+ *
+ * RETURN VALUE:
+ *  0  : The load parameter has been updated. (it should have a positive value always)
+ * !0  : An error occurred
+ */
+int fd_peer_get_load_pending(struct peer_hdr *peer, int * load);
+
 /*
  * FUNCTION:	fd_peer_validate_register
  *
--- a/libfdcore/peers.c	Tue Mar 12 15:27:30 2013 +0100
+++ b/libfdcore/peers.c	Tue Mar 12 15:27:59 2013 +0100
@@ -256,6 +256,21 @@
 	return;
 }
 
+/* Return the value of srlist->cnt */
+int fd_peer_get_load_pending(struct peer_hdr *peer, int * load)
+{
+	struct fd_peer * p = (struct fd_peer *)peer;
+	TRACE_ENTRY("%p %p", peer, load);
+	CHECK_PARAMS(CHECK_PEER(peer) && load);
+	
+	CHECK_POSIX( pthread_mutex_lock(&p->p_sr.mtx) );
+	*load = p->p_sr.cnt;
+	CHECK_POSIX( pthread_mutex_unlock(&p->p_sr.mtx) );
+	
+	return 0;
+}
+
+
 /* Destroy a structure once cleanups have been performed (fd_psm_abord, ...) */
 int fd_peer_free(struct fd_peer ** ptr)
 {
@@ -394,7 +409,7 @@
 		return;
 	}
 
-	fd_log_debug(">  %s\t%s", STATE_STR(fd_peer_getstate(peer)), peer->p_hdr.info.pi_diamid);
+	fd_log_debug(">  %s\t%s\t[%dsr]", STATE_STR(fd_peer_getstate(peer)), peer->p_hdr.info.pi_diamid, peer->p_sr.cnt);
 	if (details > INFO) {
 		fd_log_debug("\t(rlm:%s)", peer->p_hdr.info.runtime.pir_realm ?: "<unknown>");
 		if (peer->p_hdr.info.runtime.pir_prodname)
"Welcome to our mercurial repository"