diff --git a/connect.c b/connect.c
index e9c049b..d892886 100644
--- a/connect.c
+++ b/connect.c
@@ -67,9 +67,45 @@
static void net_connected(H3270 *hSession)
{
+ int err;
+ socklen_t len = sizeof(err);
+
+ trace("%s",__FUNCTION__);
RemoveSource(hSession->ns_write_id);
hSession->ns_write_id = NULL;
+ if(getsockopt(hSession->sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len) < 0)
+ {
+ lib3270_disconnect(hSession);
+ lib3270_popup_dialog( hSession,
+ LIB3270_NOTIFY_ERROR,
+ _( "Network error" ),
+ _( "Unable to get connection state." ),
+#ifdef _WIN32
+ _( "Winsock Error %d"), WSAGetLastError()
+#else
+ _( "%s" ), strerror(errno)
+#endif // _WIN32
+ );
+ return;
+ }
+ else if(err)
+ {
+ lib3270_disconnect(hSession);
+ lib3270_popup_dialog( hSession,
+ LIB3270_NOTIFY_ERROR,
+ _( "Network error" ),
+ _( "Unable to connect to server." ),
+#ifdef _WIN32
+ _( "%s"), lib3270_win32_strerror(err)
+#else
+ _( "%s" ), strerror(err)
+#endif // _WIN32
+ );
+ return;
+ }
+
+
#ifdef _WIN32
hSession->ns_exception_id = AddExcept(hSession->sockEvent, hSession, net_exception);
hSession->ns_read_id = AddInput(hSession->sockEvent, hSession, net_input);
@@ -114,7 +150,7 @@ static void net_connected(H3270 *hSession)
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "WSAStartup failed" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
@@ -223,50 +259,51 @@ static void net_connected(H3270 *hSession)
if(hSession->sock < 0)
continue;
+ trace("sock=%d",hSession->sock);
+
#ifdef WIN32
- u_long block;
- u_int len = sizeof(int);
- if(session->sockEvent == NULL)
+ if(hSession->sockEvent == NULL)
{
char ename[256];
snprintf(ename, 255, "%s-%d", PACKAGE_NAME, getpid());
- session->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename);
- if(session->sockEvent == NULL)
+ hSession->sockEvent = CreateEvent(NULL, TRUE, FALSE, ename);
+ if(hSession->sockEvent == NULL)
{
- lib3270_popup_dialog( session,
+ lib3270_popup_dialog( hSession,
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "Cannot create socket handle" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
}
- if (WSAEventSelect(session->sock, session->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0)
+ if (WSAEventSelect(hSession->sock, hSession->sockEvent, FD_READ | FD_CONNECT | FD_CLOSE) != 0)
{
- lib3270_popup_dialog( session,
+ lib3270_popup_dialog( hSession,
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "WSAEventSelect failed" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
WSASetLastError(0);
- block = 0;
+ u_long iMode=1;
+ trace("sock=%d",hSession->sock);
- if(ioctlsocket(hSession->sock,FIONBIO,&block))
+ if(ioctlsocket(hSession->sock,FIONBIO,&iMode))
{
lib3270_popup_dialog( hSession,
LIB3270_NOTIFY_ERROR,
_( "Connection error" ),
_( "ioctlsocket(FIONBIO) failed." ),
- "%s", win32_strerror(GetLastError()));
+ "%s", lib3270_win32_strerror(GetLastError()));
SOCK_CLOSE(hSession);
}
@@ -279,7 +316,7 @@ static void net_connected(H3270 *hSession)
LIB3270_NOTIFY_ERROR,
_( "Connection error" ),
_( "Can't connect to host." ),
- "%s", win32_strerror(GetLastError()));
+ "%s", lib3270_win32_strerror(GetLastError()));
SOCK_CLOSE(hSession);
}
}
@@ -342,11 +379,13 @@ static void net_connected(H3270 *hSession)
lib3270_st_changed(hSession, LIB3270_STATE_HALF_CONNECT, True);
#ifdef _WIN32
+ trace("Sockevent=%08lx callback=%p",hSession->sockEvent,net_connected);
hSession->ns_write_id = AddOutput(hSession->sockEvent, hSession, net_connected);
#else
hSession->ns_write_id = AddOutput(hSession->sock, hSession, net_connected);
#endif // WIN32
+ trace("%s: Connection in progress",__FUNCTION__);
return 0;
}
diff --git a/iocalls.c b/iocalls.c
index a3dd08d..9b71e82 100644
--- a/iocalls.c
+++ b/iocalls.c
@@ -269,8 +269,6 @@ static void * internal_add_input(int source, H3270 *session, void (*fn)(H3270 *s
{
input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t));
- trace("%s session=%p proc=%p handle=%p",__FUNCTION__,session,fn,ip);
-
ip->source = source;
ip->condition = InputReadMask;
ip->proc = fn;
@@ -290,8 +288,6 @@ static void * internal_add_output(int source, H3270 *session, void (*fn)(H3270 *
{
input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t));
- trace("%s session=%p proc=%p handle=%p",__FUNCTION__,session,fn,ip);
-
ip->source = source;
ip->condition = InputWriteMask;
ip->proc = fn;
@@ -314,8 +310,6 @@ static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *
{
input_t *ip = (input_t *) lib3270_malloc(sizeof(input_t));
- trace("%s session=%p proc=%p",__FUNCTION__,session,fn);
-
ip->source = source;
ip->condition = InputExceptMask;
ip->proc = fn;
@@ -324,7 +318,7 @@ static void * internal_add_except(int source, H3270 *session, void (*fn)(H3270 *
inputs = ip;
inputs_changed = True;
- trace("%s: fd=%d callback=%p handle=%p",__FUNCTION__,source,fn,ip);
+ trace("%s session=%p proc=%p handle=%p",__FUNCTION__,ip->session,ip->proc,ip);
return ip;
}
@@ -335,8 +329,6 @@ static void internal_remove_source(void *id)
input_t *ip;
input_t *prev = (input_t *)NULL;
- trace("%s: fhandle=%p",__FUNCTION__,(input_t *) id);
-
for (ip = inputs; ip != (input_t *)NULL; ip = ip->next)
{
if (ip == (input_t *)id)
@@ -347,7 +339,7 @@ static void internal_remove_source(void *id)
if (ip == (input_t *)NULL)
{
- lib3270_write_log(NULL,"lib3270","Double removal on %s: Input %p wasnt found in the list",__FUNCTION__,id);
+ lib3270_write_log(NULL,"lib3270","Invalid call to (%s): Input %p wasnt found in the list",__FUNCTION__,id);
return;
}
@@ -367,7 +359,6 @@ static int internal_event_dispatcher(H3270 *hSession, int block)
HANDLE ha[MAX_HA];
DWORD events;
DWORD tmo;
- DWORD ret;
unsigned long long now;
int i;
#else
@@ -376,7 +367,7 @@ static int internal_event_dispatcher(H3270 *hSession, int block)
struct timeval now, twait, *tp;
int events;
#endif
- input_t *ip, *ip_next;
+ input_t *ip;
struct timeout *t;
int processed_any = 0;
@@ -512,30 +503,41 @@ retry:
tmo = 1;
}
- ret = WaitForMultipleObjects(nha, ha, FALSE, tmo);
- if (ret == WAIT_FAILED)
+ if(events)
{
- lib3270_popup_dialog( hSession,
- LIB3270_NOTIFY_ERROR,
- _( "Network error" ),
- _( "WaitForMultipleObjects() failed when processing for events." ),
- "Windows error %d",
- GetLastError());
- }
-
- inputs_changed = False;
+ DWORD ret = WaitForMultipleObjects(events, ha, FALSE, tmo);
- for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip_next, i++)
- {
- if(ret == WAIT_OBJECT_0 + i)
+ if (ret == WAIT_FAILED)
{
- (*ip->proc)(ip->session);
- processed_any = True;
- if (inputs_changed)
- goto retry;
+ lib3270_popup_dialog( hSession,
+ LIB3270_NOTIFY_ERROR,
+ _( "Network error" ),
+ _( "WaitForMultipleObjects() failed when processing for events." ),
+ "%s",
+ lib3270_win32_strerror(GetLastError()));
+ lib3270_disconnect(hSession);
}
+ else
+ {
+ inputs_changed = False;
+ for (i = 0, ip = inputs; ip != (input_t *)NULL; ip = ip->next, i++)
+ {
+ if(ret == WAIT_OBJECT_0 + i)
+ {
+ (*ip->proc)(ip->session);
+ processed_any = True;
+ if (inputs_changed)
+ goto retry;
+ }
+ }
+ }
+ }
+ else if(block)
+ {
+ Sleep(100);
}
+
#else
FD_ZERO(&rfds);
@@ -606,10 +608,8 @@ retry:
}
else
{
- for (ip = inputs; ip != (input_t *) NULL; ip = ip_next)
+ for (ip = inputs; ip != (input_t *) NULL; ip = ip->next)
{
- ip_next = ip->next;
-
if (((unsigned long)ip->condition & InputReadMask) && FD_ISSET(ip->source, &rfds))
{
(*ip->proc)(ip->session);
diff --git a/kybd.c b/kybd.c
index 9e8caa1..5dc967c 100644
--- a/kybd.c
+++ b/kybd.c
@@ -399,7 +399,7 @@ void lib3270_kybdlock_clear(H3270 *hSession, LIB3270_KL_STATE bits)
{
unsigned int n = hSession->kybdlock & ~( (unsigned int) bits);
- trace("%s: kybdlock=%d",__FUNCTION__,n);
+// trace("%s: kybdlock=%d",__FUNCTION__,n);
if (n != hSession->kybdlock)
{
diff --git a/lib3270.cbp b/lib3270.cbp
index 75713c5..c3cd57d 100644
--- a/lib3270.cbp
+++ b/lib3270.cbp
@@ -15,9 +15,6 @@
-
-
-
@@ -50,16 +47,17 @@
-
+
-
-
-
+
+
+
+
diff --git a/telnet.c b/telnet.c
index e27d232..ae7c433 100644
--- a/telnet.c
+++ b/telnet.c
@@ -315,7 +315,7 @@ void sockstart(H3270 *session)
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "WSAStartup failed" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
@@ -344,7 +344,7 @@ socklen_t ha_len = sizeof(haddr);
void popup_a_sockerr(H3270 *hSession, char *fmt, ...)
{
#if defined(_WIN32)
- const char *msg = win32_strerror(socket_errno());
+ const char *msg = lib3270_win32_strerror(socket_errno());
#else
const char *msg = strerror(errno);
#endif // WIN32
@@ -719,7 +719,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "Cannot create socket handle" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
}
@@ -730,7 +730,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
LIB3270_NOTIFY_CRITICAL,
N_( "Network startup error" ),
N_( "WSAEventSelect failed" ),
- "%s", win32_strerror(GetLastError()) );
+ "%s", lib3270_win32_strerror(GetLastError()) );
_exit(1);
}
@@ -1069,7 +1069,7 @@ LIB3270_EXPORT void lib3270_data_recv(H3270 *hSession, size_t nr, const unsigned
{
register const unsigned char * cp;
- trace("%s: nr=%d",__FUNCTION__,(int) nr);
+// trace("%s: nr=%d",__FUNCTION__,(int) nr);
trace_netdata(hSession, '<', netrbuf, nr);
@@ -3284,7 +3284,7 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret)
#if defined(_WIN32)
else if (GetLastError() != 0)
{
- strncpy(err_buf,win32_strerror(GetLastError()),1023);
+ strncpy(err_buf,lib3270_win32_strerror(GetLastError()),1023);
}
#else
else if (errno != 0)
diff --git a/testprogram.c b/testprogram.c
index ec66e5b..f6e0e4e 100644
--- a/testprogram.c
+++ b/testprogram.c
@@ -1,15 +1,13 @@
#include
#include
-#include
+// #include
#include "globals.h"
#include
#define MAX_ARGS 10
-#include
-
static H3270 *session = NULL;
static void * mainloop(void *dunno)
@@ -25,18 +23,22 @@ int main(int numpar, char *param[])
{
H3270 * h;
char line[4096];
- pthread_t thread;
+// pthread_t thread;
lib3270_initialize();
session = h = lib3270_session_new("");
printf("3270 session %p created\n]",h);
- pthread_create(&thread, NULL, mainloop, NULL);
- pthread_detach(thread);
+// pthread_create(&thread, NULL, mainloop, NULL);
+// pthread_detach(thread);
+
+ lib3270_connect_host(h, "fandezhi.efglobe.com", "telnet");
+// lib3270_connect_host(h, "127.0.0.1", "9090");
- lib3270_connect_host(h, "127.0.0.1", "80");
+ mainloop(0);
+/*
while(fgets(line,4095,stdin))
{
// const LIB3270_MACRO_LIST *cmd = get_3270_calls();
@@ -85,6 +87,7 @@ int main(int numpar, char *param[])
printf("Ending 3270 session %p\n",h);
lib3270_session_free(h);
+*/
return 0;
}
diff --git a/util.c b/util.c
index e34c9c8..0459329 100644
--- a/util.c
+++ b/util.c
@@ -146,25 +146,16 @@ const char * inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
}
// Decode a Win32 error number.
-const char * win32_strerror(int e)
+LIB3270_EXPORT const char * lib3270_win32_strerror(int e)
{
static char buffer[4096];
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- e,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- buffer,
- sizeof(buffer),
- NULL) == 0) {
-
- sprintf(buffer, "Windows error %d", e);
- }
+ if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,e,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,sizeof(buffer),NULL) == 0)
+ snprintf(buffer, 4095, "Windows error %d", e);
return buffer;
}
-
#endif // _WIN32
/*
--
libgit2 0.21.2