diff --git a/client/src/core/windows/request.cc b/client/src/core/windows/request.cc index eb41978..7178271 100644 --- a/client/src/core/windows/request.cc +++ b/client/src/core/windows/request.cc @@ -147,7 +147,16 @@ uint16_t rc = *((uint16_t *) (in.block + in.current)); in.current += sizeof(uint16_t); - // Extract argc + if(rc) { + + // It´s an error, extract message + in.block[in.used] = 0; + debug("Error was ",rc," (\"",(const char *) (in.block + in.current),"\")"); + throw std::system_error(std::error_code(rc,std::system_category()),(const char *) (in.block + in.current)); + + } + + // It´s not an error, extract argument count uint16_t argc = *((uint16_t *) (in.block + in.current)); in.current += sizeof(uint16_t); diff --git a/client/src/host/pop.cc b/client/src/host/pop.cc index 9ccb81f..fc3d6e7 100644 --- a/client/src/host/pop.cc +++ b/client/src/host/pop.cc @@ -41,41 +41,17 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ TN3270::Host & TN3270::Host::pop(int baddr, std::string &text) { - - this->session->waitForReady(this->timeout); - - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { - chkResponse(ENOTCONN); - } - session->pop(baddr, text); - return *this; } TN3270::Host & TN3270::Host::pop(unsigned short row, unsigned short col, std::string &text) { - - this->session->waitForReady(this->timeout); - - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { - chkResponse(ENOTCONN); - } - session->pop(row,col,text); - return *this; } TN3270::Host & TN3270::Host::pop(std::string &text) { - - this->session->waitForReady(this->timeout); - - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { - chkResponse(ENOTCONN); - } - session->pop(text); - return *this; } diff --git a/client/src/host/stream.cc b/client/src/host/stream.cc index 57f8fcf..9102bd7 100644 --- a/client/src/host/stream.cc +++ b/client/src/host/stream.cc @@ -42,7 +42,6 @@ /// @brief Writes characters to the associated file from the put area int TN3270::Host::sync() { - this->session->waitForReady(this->timeout); return 0; } diff --git a/client/src/host/string.cc b/client/src/host/string.cc index 09178f8..c1264d0 100644 --- a/client/src/host/string.cc +++ b/client/src/host/string.cc @@ -41,52 +41,32 @@ /*---[ Implement ]----------------------------------------------------------------------------------*/ std::string TN3270::Host::toString() const { - - this->session->waitForReady(this->timeout); return this->session->toString(); } std::string TN3270::Host::toString(int baddr, int len, char lf) const { - - this->session->waitForReady(this->timeout); return this->session->toString(baddr,len,lf); - } std::string TN3270::Host::toString(unsigned short row, unsigned short col, int len, char lf) const { - - this->session->waitForReady(this->timeout); return this->session->toString(row,col,len,lf); - } /// @brief Checks if the terminal contains the string. size_t TN3270::Host::find(const char * str, size_t pos) const { - - this->session->waitForReady(this->timeout); return this->session->find(str,pos); - } /// @brief Get the number of occurrences of a string in the terminal. size_t TN3270::Host::count(const char * str, size_t pos) const { - - this->session->waitForReady(this->timeout); return this->session->count(str,pos); - } /// @brief Compare contents. int TN3270::Host::compare(int baddr, const char* s, int len) const { - - this->session->waitForReady(this->timeout); return this->session->compare(baddr, s, len); - } int TN3270::Host::compare(unsigned short row, unsigned short col, const char* s, int len) const { - - this->session->waitForReady(this->timeout); return this->session->compare(row,col,s,len); - } diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index 072a64d..bf22390 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -170,25 +170,13 @@ TN3270::Host host{session}; - host.connect(); + // host.connect(); - { - auto start = time(nullptr); - for(size_t ix = 0; ix < 100; ix++) { - host.waitForReady(5); - } - cout << endl << "Time for waitForReady method: " << (time(nullptr) - start) << endl << endl; - } + cout << endl << "------------------------" << endl; + host.toString(14,1,75,0); + cout << endl << "------------------------" << endl; - { - auto start = time(nullptr); - for(size_t ix = 0; ix < 100; ix++) { - host.toString(14,1,80,0); - } - cout << endl << "Time for toString method: " << (time(nullptr) - start) << endl << endl; - } - - host.disconnect(); + // host.disconnect(); /* cout @@ -275,8 +263,8 @@ cout << "Session: " << session << endl; - // testHost(session); - testPerformance(session); + testHost(session); + // testPerformance(session); //testAttributes(session); diff --git a/server/src/core/linux/gobject.c b/server/src/core/linux/gobject.c index f030a42..041d4da 100644 --- a/server/src/core/linux/gobject.c +++ b/server/src/core/linux/gobject.c @@ -302,11 +302,6 @@ H3270 * ipc3270_get_session(GObject *object) { return IPC3270(object)->hSession; } -void ipc3270_set_error(GObject *object, int errcode, GError **error) { - if(error && !*error) - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); -} - GQuark ipc3270_get_error_domain(GObject *object) { return IPC3270(object)->error_domain; } diff --git a/server/src/core/methods/methods.c b/server/src/core/methods/methods.c index 85e74d9..d84aba3 100644 --- a/server/src/core/methods/methods.c +++ b/server/src/core/methods/methods.c @@ -88,12 +88,21 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req if(!g_ascii_strcasecmp(methods[ix].name,method_name)) { +#ifdef _DEBUG_ + g_message("Calling %s",methods[ix].name); +#endif // _DEBUG_ + int rc = methods[ix].call(object,request,response,error); debug("rc=%d error=%p",rc,*error); if(rc) + { + debug("%s exits with rc=%d (%s)",methods[ix].name,rc,ipc3270_get_error_message(rc)); + g_message("%s exits with rc=%d (%s)",methods[ix].name,rc,ipc3270_get_error_message(rc)); ipc3270_set_error(object,rc,error); + debug("Error Message was set to %s",(*error)->message); + } return 0; } diff --git a/server/src/core/tools.c b/server/src/core/tools.c index 074e43b..146fca2 100644 --- a/server/src/core/tools.c +++ b/server/src/core/tools.c @@ -43,3 +43,30 @@ #endif // ! GLIB(2,44,0) + const char * ipc3270_get_error_message(int errcode) { + + static const struct Messages { + int errcode; + const char *msg; + } messages[] = { + { ENOTCONN, "Not connected to host" } + }; + + size_t ix; + + for(ix = 0; ix < G_N_ELEMENTS(messages); ix++) { + if(messages[ix].errcode == errcode) { + return messages[ix].msg; + } + } + + return strerror(errcode); +} + +void ipc3270_set_error(GObject *object, int errcode, GError **error) { + if(error && !*error) { + g_set_error(error,ipc3270_get_error_domain(object),errcode,"%s",ipc3270_get_error_message(errcode)); + } +} + + diff --git a/server/src/core/windows/gobject.c b/server/src/core/windows/gobject.c index 646aa2a..e2fc4ac 100644 --- a/server/src/core/windows/gobject.c +++ b/server/src/core/windows/gobject.c @@ -112,10 +112,6 @@ H3270 * ipc3270_get_session(GObject *object) { return IPC3270(object)->hSession; } -void ipc3270_set_error(GObject *object, int errcode, GError **error) { - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); -} - GQuark ipc3270_get_error_domain(GObject *object) { return IPC3270(object)->error_domain; } diff --git a/server/src/include/ipc-glib.h b/server/src/include/ipc-glib.h index bee9e20..95ef7b7 100644 --- a/server/src/include/ipc-glib.h +++ b/server/src/include/ipc-glib.h @@ -139,6 +139,7 @@ GQuark ipc3270_get_error_domain(GObject *object); void ipc3270_set_error(GObject *object, int errcode, GError **error); + const char * ipc3270_get_error_message(int errcode); int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error); gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); -- libgit2 0.21.2