Subject: [libssh2] [PATCH] AIX build fix

[libssh2] [PATCH] AIX build fix

From: Tor Arntsen <tor_at_spacetec.no>
Date: Thu, 23 Nov 2006 18:17:14 +0100

Hi,

Following is a suggested fix to make libssh2 compile on AIX 5.x (and also
4.x, afaik).

The problem is that AIX has these defines in /usr/include/sys/poll.h:

#define events reqevents /* SVR3,4 pollfd member name */
#define revents rtnevents /* SVR3,4 pollfd member name */
if compiled 32-bits (i.e. default).

This messes up the 'events' and 'revents' fields in struct _LIBSH2_POLLFD
and causes lots of
session.c: In function `libssh2_poll':
session.c:757: error: structure has no member named `rtnevents'
session.c:761: error: structure has no member named `reqevents'
session.c:834: error: structure has no member named `reqevents'
session.c:834: error: structure has no member named `rtnevents'
..etc.

The suggested fix (below) is to rename the _LIBSSH2_POLLFD fields,
I have used ssh2events, ssh2revents in order to create a private namespace.
This fixes the AIX build problem, and ssh2_sample works, so far so good.

Let me know what you think.

-Tor (tor2)
(p.s. libssh2 currently only compiles with gcc on AIX, to build it with
the IBM compiler needs further work.)

--
Index: include/libssh2.h
===================================================================
RCS file: /cvsroot/libssh2/libssh2/include/libssh2.h,v
retrieving revision 1.60
diff -u -p -r1.60 libssh2.h
--- include/libssh2.h	4 Nov 2006 19:30:31 -0000	1.60
+++ include/libssh2.h	23 Nov 2006 17:06:42 -0000
@@ -172,8 +172,8 @@ typedef struct _LIBSSH2_POLLFD {
 		LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */
 	} fd;
 
-	unsigned long events; /* Requested Events */
-	unsigned long revents; /* Returned Events */
+	unsigned long ssh2events; /* Requested Events */
+	unsigned long ssh2revents; /* Returned Events */
 } LIBSSH2_POLLFD;
 
 /* Poll FD Descriptor Types */
Index: src/session.c
===================================================================
RCS file: /cvsroot/libssh2/libssh2/src/session.c,v
retrieving revision 1.27
diff -u -p -r1.27 session.c
--- src/session.c	17 Apr 2006 02:49:44 -0000	1.27
+++ src/session.c	23 Nov 2006 17:06:42 -0000
@@ -754,11 +754,11 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 
 	/* Setup sockets for polling */
 	for(i = 0; i < nfds; i++) {
-		fds[i].revents = 0;
+		fds[i].ssh2revents = 0;
 		switch (fds[i].type) {
 			case LIBSSH2_POLLFD_SOCKET:
 				sockets[i].fd = fds[i].fd.socket;
-				sockets[i].events  = fds[i].events;
+				sockets[i].events  = fds[i].ssh2events;
 				sockets[i].revents = 0;
 				break;
 			case LIBSSH2_POLLFD_CHANNEL:
@@ -787,14 +787,14 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 	FD_ZERO(&rfds);
 	FD_ZERO(&wfds);
 	for(i = 0; i < nfds; i++) {
-		fds[i].revents = 0;
+		fds[i].ssh2revents = 0;
 		switch (fds[i].type) {
 			case LIBSSH2_POLLFD_SOCKET:
-				if (fds[i].events & LIBSSH2_POLLFD_POLLIN) {
+				if (fds[i].ssh2events & LIBSSH2_POLLFD_POLLIN) {
 					FD_SET(fds[i].fd.socket, &rfds);
 					if (fds[i].fd.socket > maxfd) maxfd = fds[i].fd.socket;
 				}
-				if (fds[i].events & LIBSSH2_POLLFD_POLLOUT) {
+				if (fds[i].ssh2events & LIBSSH2_POLLFD_POLLOUT) {
 					FD_SET(fds[i].fd.socket, &wfds);
 					if (fds[i].fd.socket > maxfd) maxfd = fds[i].fd.socket;
 				}
@@ -831,40 +831,40 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 		active_fds = 0;
 
 		for (i = 0; i < nfds; i++) {
-			if (fds[i].events != fds[i].revents) {
+			if (fds[i].ssh2events != fds[i].ssh2revents) {
 				switch (fds[i].type) {
 					case LIBSSH2_POLLFD_CHANNEL:
-						if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want to be ready for read */
-							((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* Not yet known to be ready for read */
-							fds[i].revents |= libssh2_poll_channel_read(fds[i].fd.channel, 0) ? LIBSSH2_POLLFD_POLLIN : 0;
-						}
-						if ((fds[i].events & LIBSSH2_POLLFD_POLLEXT) && /* Want to be ready for extended read */
-							((fds[i].revents & LIBSSH2_POLLFD_POLLEXT) == 0)) { /* Not yet known to be ready for extended read */
-							fds[i].revents |= libssh2_poll_channel_read(fds[i].fd.channel, 1) ? LIBSSH2_POLLFD_POLLEXT : 0;
-						}
-						if ((fds[i].events & LIBSSH2_POLLFD_POLLOUT) && /* Want to be ready for write */
-							((fds[i].revents & LIBSSH2_POLLFD_POLLOUT) == 0)) { /* Not yet known to be ready for write */
-							fds[i].revents |= libssh2_poll_channel_write(fds[i].fd.channel) ? LIBSSH2_POLLFD_POLLOUT : 0;
+						if ((fds[i].ssh2events & LIBSSH2_POLLFD_POLLIN) && /* Want to be ready for read */
+							((fds[i].ssh2revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* Not yet known to be ready for read */
+							fds[i].ssh2revents |= libssh2_poll_channel_read(fds[i].fd.channel, 0) ? LIBSSH2_POLLFD_POLLIN : 0;
+						}
+						if ((fds[i].ssh2events & LIBSSH2_POLLFD_POLLEXT) && /* Want to be ready for extended read */
+							((fds[i].ssh2revents & LIBSSH2_POLLFD_POLLEXT) == 0)) { /* Not yet known to be ready for extended read */
+							fds[i].ssh2revents |= libssh2_poll_channel_read(fds[i].fd.channel, 1) ? LIBSSH2_POLLFD_POLLEXT : 0;
+						}
+						if ((fds[i].ssh2events & LIBSSH2_POLLFD_POLLOUT) && /* Want to be ready for write */
+							((fds[i].ssh2revents & LIBSSH2_POLLFD_POLLOUT) == 0)) { /* Not yet known to be ready for write */
+							fds[i].ssh2revents |= libssh2_poll_channel_write(fds[i].fd.channel) ? LIBSSH2_POLLFD_POLLOUT : 0;
 						}
 						if (fds[i].fd.channel->remote.close || fds[i].fd.channel->local.close) {
-							fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED;
 						}
 						if (fds[i].fd.channel->session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
-							fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
 						}
 						break;
 					case LIBSSH2_POLLFD_LISTENER:
-						if ((fds[i].events & LIBSSH2_POLLFD_POLLIN) && /* Want a connection */
-							((fds[i].revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* No connections known of yet */
-							fds[i].revents |= libssh2_poll_listener_queued(fds[i].fd.listener) ? LIBSSH2_POLLFD_POLLIN : 0;
+						if ((fds[i].ssh2events & LIBSSH2_POLLFD_POLLIN) && /* Want a connection */
+							((fds[i].ssh2revents & LIBSSH2_POLLFD_POLLIN) == 0)) { /* No connections known of yet */
+							fds[i].ssh2revents |= libssh2_poll_listener_queued(fds[i].fd.listener) ? LIBSSH2_POLLFD_POLLIN : 0;
 						}
 						if (fds[i].fd.listener->session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
-							fds[i].revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
 						}
 						break;
 				}
 			}
-			if (fds[i].revents) {
+			if (fds[i].ssh2revents) {
 				active_fds++;
 			}
 		}
@@ -898,9 +898,9 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 			for (i = 0; i < nfds; i++) {
 				switch (fds[i].type) {
 					case LIBSSH2_POLLFD_SOCKET:
-						fds[i].revents = sockets[i].revents;
+						fds[i].ssh2revents = sockets[i].revents;
 						sockets[i].revents = 0; /* In case we loop again, be nice */
-						if (fds[i].revents) {
+						if (fds[i].ssh2revents) {
 							active_fds++;
 						}
 						break;
@@ -910,7 +910,7 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 							while (libssh2_packet_read(fds[i].fd.channel->session, 0) > 0);
 						}
 						if (sockets[i].revents & POLLHUP) {
-							fds[i].revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_CHANNEL_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
 						}
 						sockets[i].revents = 0;
 						break;
@@ -920,7 +920,7 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 							while (libssh2_packet_read(fds[i].fd.listener->session, 0) > 0);
 						}
 						if (sockets[i].revents & POLLHUP) {
-							fds[i].revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_LISTENER_CLOSED | LIBSSH2_POLLFD_SESSION_CLOSED;
 						}
 						sockets[i].revents = 0;
 						break;
@@ -954,12 +954,12 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POL
 				switch (fds[i].type) {
 					case LIBSSH2_POLLFD_SOCKET:
 						if (FD_ISSET(fds[i].fd.socket, &rfds)) {
-							fds[i].revents |= LIBSSH2_POLLFD_POLLIN;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_POLLIN;
 						}
 						if (FD_ISSET(fds[i].fd.socket, &wfds)) {
-							fds[i].revents |= LIBSSH2_POLLFD_POLLOUT;
+							fds[i].ssh2revents |= LIBSSH2_POLLFD_POLLOUT;
 						}
-						if (fds[i].revents) {
+						if (fds[i].ssh2revents) {
 							active_fds++;
 						}
 						break;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2006-11-23