summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2010-06-29 23:38:39 +0200
committerAlexander Barton <alex@barton.de>2010-06-29 23:38:39 +0200
commit3d49fa5bffac43f2fcf535c8b1aedae732d1f9f5 (patch)
treedc636d71f396d4f5a1296442d0a71a3be2586e42 /src
parent2d4ea288353c2240c8d13e41c8da1557fc32168b (diff)
downloadngircd-3d49fa5bffac43f2fcf535c8b1aedae732d1f9f5.tar.gz
ngircd-3d49fa5bffac43f2fcf535c8b1aedae732d1f9f5.zip
New function Conn_GetFromProc() to get CONN_ID of a subprocess
Get CONN_ID from file descriptor associated to a subprocess structure.
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conn.c32
-rw-r--r--src/ngircd/conn.h1
2 files changed, 24 insertions, 9 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 0d82d530..4df1e9e4 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1986,7 +1986,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
 	 * IDENT user name.*/
 
 	CLIENT *c;
-	int i;
+	CONN_ID i;
 	size_t len;
 	char *identptr;
 #ifdef IDENTAUTH
@@ -1996,14 +1996,8 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
 #endif
 
 	LogDebug("Resolver: Got callback on fd %d, events %d", r_fd, events );
-
-	/* Search associated connection ... */
-	for( i = 0; i < Pool_Size; i++ ) {
-		if(( My_Connections[i].sock != NONE )
-		  && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == r_fd))
-			break;
-	}
-	if( i >= Pool_Size ) {
+	i = Conn_GetFromProc(r_fd);
+	if (i == NONE) {
 		/* Ops, none found? Probably the connection has already
 		 * been closed!? We'll ignore that ... */
 		io_close( r_fd );
@@ -2108,6 +2102,26 @@ Conn_GetClient( CONN_ID Idx )
 }
 
 
+/**
+ * Get CONN_ID from file descriptor associated to a subprocess structure.
+ * @param fd File descriptor
+ * @return CONN_ID or NONE (-1)
+ */
+GLOBAL CONN_ID
+Conn_GetFromProc(int fd)
+{
+	int i;
+
+	assert(fd > 0);
+	for (i = 0; i < Pool_Size; i++) {
+		if ((My_Connections[i].sock != NONE)
+		    && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == fd))
+			return i;
+	}
+	return NONE;
+} /* Conn_GetFromProc */
+
+
 #ifdef SSL_SUPPORT
 
 /**
diff --git a/src/ngircd/conn.h b/src/ngircd/conn.h
index 7665bb37..e9b470bc 100644
--- a/src/ngircd/conn.h
+++ b/src/ngircd/conn.h
@@ -113,6 +113,7 @@ GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *Fwd
 
 GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
 
+GLOBAL CONN_ID Conn_GetFromProc PARAMS((int fd));
 GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
 #ifdef SSL_SUPPORT
 GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));