Commit b6bfda0d46fd608e56166e98d8a40e7355f8da8a
1 parent
dff8b36d
Exists in
master
and in
1 other branch
Fixing windows error messages.
Showing
10 changed files
with
54 additions
and
74 deletions
Show diff stats
client/src/core/windows/request.cc
| ... | ... | @@ -147,7 +147,16 @@ |
| 147 | 147 | uint16_t rc = *((uint16_t *) (in.block + in.current)); |
| 148 | 148 | in.current += sizeof(uint16_t); |
| 149 | 149 | |
| 150 | - // Extract argc | |
| 150 | + if(rc) { | |
| 151 | + | |
| 152 | + // It´s an error, extract message | |
| 153 | + in.block[in.used] = 0; | |
| 154 | + debug("Error was ",rc," (\"",(const char *) (in.block + in.current),"\")"); | |
| 155 | + throw std::system_error(std::error_code(rc,std::system_category()),(const char *) (in.block + in.current)); | |
| 156 | + | |
| 157 | + } | |
| 158 | + | |
| 159 | + // It´s not an error, extract argument count | |
| 151 | 160 | uint16_t argc = *((uint16_t *) (in.block + in.current)); |
| 152 | 161 | in.current += sizeof(uint16_t); |
| 153 | 162 | ... | ... |
client/src/host/pop.cc
| ... | ... | @@ -41,41 +41,17 @@ |
| 41 | 41 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 42 | 42 | |
| 43 | 43 | TN3270::Host & TN3270::Host::pop(int baddr, std::string &text) { |
| 44 | - | |
| 45 | - this->session->waitForReady(this->timeout); | |
| 46 | - | |
| 47 | - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { | |
| 48 | - chkResponse(ENOTCONN); | |
| 49 | - } | |
| 50 | - | |
| 51 | 44 | session->pop(baddr, text); |
| 52 | - | |
| 53 | 45 | return *this; |
| 54 | 46 | } |
| 55 | 47 | |
| 56 | 48 | TN3270::Host & TN3270::Host::pop(unsigned short row, unsigned short col, std::string &text) { |
| 57 | - | |
| 58 | - this->session->waitForReady(this->timeout); | |
| 59 | - | |
| 60 | - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { | |
| 61 | - chkResponse(ENOTCONN); | |
| 62 | - } | |
| 63 | - | |
| 64 | 49 | session->pop(row,col,text); |
| 65 | - | |
| 66 | 50 | return *this; |
| 67 | 51 | } |
| 68 | 52 | |
| 69 | 53 | TN3270::Host & TN3270::Host::pop(std::string &text) { |
| 70 | - | |
| 71 | - this->session->waitForReady(this->timeout); | |
| 72 | - | |
| 73 | - if(this->session->getConnectionState() == TN3270::DISCONNECTED) { | |
| 74 | - chkResponse(ENOTCONN); | |
| 75 | - } | |
| 76 | - | |
| 77 | 54 | session->pop(text); |
| 78 | - | |
| 79 | 55 | return *this; |
| 80 | 56 | } |
| 81 | 57 | ... | ... |
client/src/host/stream.cc
client/src/host/string.cc
| ... | ... | @@ -41,52 +41,32 @@ |
| 41 | 41 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
| 42 | 42 | |
| 43 | 43 | std::string TN3270::Host::toString() const { |
| 44 | - | |
| 45 | - this->session->waitForReady(this->timeout); | |
| 46 | 44 | return this->session->toString(); |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | std::string TN3270::Host::toString(int baddr, int len, char lf) const { |
| 50 | - | |
| 51 | - this->session->waitForReady(this->timeout); | |
| 52 | 48 | return this->session->toString(baddr,len,lf); |
| 53 | - | |
| 54 | 49 | } |
| 55 | 50 | |
| 56 | 51 | std::string TN3270::Host::toString(unsigned short row, unsigned short col, int len, char lf) const { |
| 57 | - | |
| 58 | - this->session->waitForReady(this->timeout); | |
| 59 | 52 | return this->session->toString(row,col,len,lf); |
| 60 | - | |
| 61 | 53 | } |
| 62 | 54 | |
| 63 | 55 | /// @brief Checks if the terminal contains the string. |
| 64 | 56 | size_t TN3270::Host::find(const char * str, size_t pos) const { |
| 65 | - | |
| 66 | - this->session->waitForReady(this->timeout); | |
| 67 | 57 | return this->session->find(str,pos); |
| 68 | - | |
| 69 | 58 | } |
| 70 | 59 | |
| 71 | 60 | /// @brief Get the number of occurrences of a string in the terminal. |
| 72 | 61 | size_t TN3270::Host::count(const char * str, size_t pos) const { |
| 73 | - | |
| 74 | - this->session->waitForReady(this->timeout); | |
| 75 | 62 | return this->session->count(str,pos); |
| 76 | - | |
| 77 | 63 | } |
| 78 | 64 | |
| 79 | 65 | /// @brief Compare contents. |
| 80 | 66 | int TN3270::Host::compare(int baddr, const char* s, int len) const { |
| 81 | - | |
| 82 | - this->session->waitForReady(this->timeout); | |
| 83 | 67 | return this->session->compare(baddr, s, len); |
| 84 | - | |
| 85 | 68 | } |
| 86 | 69 | |
| 87 | 70 | int TN3270::Host::compare(unsigned short row, unsigned short col, const char* s, int len) const { |
| 88 | - | |
| 89 | - this->session->waitForReady(this->timeout); | |
| 90 | 71 | return this->session->compare(row,col,s,len); |
| 91 | - | |
| 92 | 72 | } | ... | ... |
client/src/testprogram/testprogram.cc
| ... | ... | @@ -170,25 +170,13 @@ |
| 170 | 170 | |
| 171 | 171 | TN3270::Host host{session}; |
| 172 | 172 | |
| 173 | - host.connect(); | |
| 173 | + // host.connect(); | |
| 174 | 174 | |
| 175 | - { | |
| 176 | - auto start = time(nullptr); | |
| 177 | - for(size_t ix = 0; ix < 100; ix++) { | |
| 178 | - host.waitForReady(5); | |
| 179 | - } | |
| 180 | - cout << endl << "Time for waitForReady method: " << (time(nullptr) - start) << endl << endl; | |
| 181 | - } | |
| 175 | + cout << endl << "------------------------" << endl; | |
| 176 | + host.toString(14,1,75,0); | |
| 177 | + cout << endl << "------------------------" << endl; | |
| 182 | 178 | |
| 183 | - { | |
| 184 | - auto start = time(nullptr); | |
| 185 | - for(size_t ix = 0; ix < 100; ix++) { | |
| 186 | - host.toString(14,1,80,0); | |
| 187 | - } | |
| 188 | - cout << endl << "Time for toString method: " << (time(nullptr) - start) << endl << endl; | |
| 189 | - } | |
| 190 | - | |
| 191 | - host.disconnect(); | |
| 179 | + // host.disconnect(); | |
| 192 | 180 | |
| 193 | 181 | /* |
| 194 | 182 | cout |
| ... | ... | @@ -275,8 +263,8 @@ |
| 275 | 263 | |
| 276 | 264 | cout << "Session: " << session << endl; |
| 277 | 265 | |
| 278 | - // testHost(session); | |
| 279 | - testPerformance(session); | |
| 266 | + testHost(session); | |
| 267 | + // testPerformance(session); | |
| 280 | 268 | |
| 281 | 269 | |
| 282 | 270 | //testAttributes(session); | ... | ... |
server/src/core/linux/gobject.c
| ... | ... | @@ -302,11 +302,6 @@ H3270 * ipc3270_get_session(GObject *object) { |
| 302 | 302 | return IPC3270(object)->hSession; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | -void ipc3270_set_error(GObject *object, int errcode, GError **error) { | |
| 306 | - if(error && !*error) | |
| 307 | - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); | |
| 308 | -} | |
| 309 | - | |
| 310 | 305 | GQuark ipc3270_get_error_domain(GObject *object) { |
| 311 | 306 | return IPC3270(object)->error_domain; |
| 312 | 307 | } | ... | ... |
server/src/core/methods/methods.c
| ... | ... | @@ -88,12 +88,21 @@ int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *req |
| 88 | 88 | |
| 89 | 89 | if(!g_ascii_strcasecmp(methods[ix].name,method_name)) { |
| 90 | 90 | |
| 91 | +#ifdef _DEBUG_ | |
| 92 | + g_message("Calling %s",methods[ix].name); | |
| 93 | +#endif // _DEBUG_ | |
| 94 | + | |
| 91 | 95 | int rc = methods[ix].call(object,request,response,error); |
| 92 | 96 | |
| 93 | 97 | debug("rc=%d error=%p",rc,*error); |
| 94 | 98 | |
| 95 | 99 | if(rc) |
| 100 | + { | |
| 101 | + debug("%s exits with rc=%d (%s)",methods[ix].name,rc,ipc3270_get_error_message(rc)); | |
| 102 | + g_message("%s exits with rc=%d (%s)",methods[ix].name,rc,ipc3270_get_error_message(rc)); | |
| 96 | 103 | ipc3270_set_error(object,rc,error); |
| 104 | + debug("Error Message was set to %s",(*error)->message); | |
| 105 | + } | |
| 97 | 106 | |
| 98 | 107 | return 0; |
| 99 | 108 | } | ... | ... |
server/src/core/tools.c
| ... | ... | @@ -43,3 +43,30 @@ |
| 43 | 43 | |
| 44 | 44 | #endif // ! GLIB(2,44,0) |
| 45 | 45 | |
| 46 | + const char * ipc3270_get_error_message(int errcode) { | |
| 47 | + | |
| 48 | + static const struct Messages { | |
| 49 | + int errcode; | |
| 50 | + const char *msg; | |
| 51 | + } messages[] = { | |
| 52 | + { ENOTCONN, "Not connected to host" } | |
| 53 | + }; | |
| 54 | + | |
| 55 | + size_t ix; | |
| 56 | + | |
| 57 | + for(ix = 0; ix < G_N_ELEMENTS(messages); ix++) { | |
| 58 | + if(messages[ix].errcode == errcode) { | |
| 59 | + return messages[ix].msg; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + return strerror(errcode); | |
| 64 | +} | |
| 65 | + | |
| 66 | +void ipc3270_set_error(GObject *object, int errcode, GError **error) { | |
| 67 | + if(error && !*error) { | |
| 68 | + g_set_error(error,ipc3270_get_error_domain(object),errcode,"%s",ipc3270_get_error_message(errcode)); | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | + | ... | ... |
server/src/core/windows/gobject.c
| ... | ... | @@ -112,10 +112,6 @@ H3270 * ipc3270_get_session(GObject *object) { |
| 112 | 112 | return IPC3270(object)->hSession; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | -void ipc3270_set_error(GObject *object, int errcode, GError **error) { | |
| 116 | - g_set_error(error,IPC3270(object)->error_domain,errcode,"%s",strerror(errcode)); | |
| 117 | -} | |
| 118 | - | |
| 119 | 115 | GQuark ipc3270_get_error_domain(GObject *object) { |
| 120 | 116 | return IPC3270(object)->error_domain; |
| 121 | 117 | } | ... | ... |
server/src/include/ipc-glib.h
| ... | ... | @@ -139,6 +139,7 @@ |
| 139 | 139 | GQuark ipc3270_get_error_domain(GObject *object); |
| 140 | 140 | |
| 141 | 141 | void ipc3270_set_error(GObject *object, int errcode, GError **error); |
| 142 | + const char * ipc3270_get_error_message(int errcode); | |
| 142 | 143 | |
| 143 | 144 | int ipc3270_method_call(GObject *object, const gchar *method_name, GVariant *request, GObject *response, GError **error); |
| 144 | 145 | gboolean ipc3270_set_property(GObject *object, const gchar *property_name, GVariant *value, GError **error); | ... | ... |