Commit acd6645704c51cb29d626ca19d0a4c1e0bc1f2ee
1 parent
6d33c974
Exists in
master
and in
1 other branch
Fixing small bugs.
Showing
4 changed files
with
32 additions
and
39 deletions
Show diff stats
client/src/include/ipc-client-internals.h
... | ... | @@ -165,6 +165,9 @@ |
165 | 165 | /// @brief Wait for network events |
166 | 166 | void wait(time_t timeout = 5); |
167 | 167 | |
168 | + /// @brief Check lib3270 return codes, launch exception when failed. | |
169 | + static void chkResponse(int rc); | |
170 | + | |
168 | 171 | public: |
169 | 172 | Session(); |
170 | 173 | virtual ~Session(); | ... | ... |
client/src/session/local/session.cc
... | ... | @@ -40,6 +40,7 @@ |
40 | 40 | #include <lib3270/actions.h> |
41 | 41 | #include <lib3270/properties.h> |
42 | 42 | #include <lib3270/toggle.h> |
43 | + #include <iostream> | |
43 | 44 | #include <cstring> |
44 | 45 | |
45 | 46 | extern "C" { |
... | ... | @@ -83,26 +84,30 @@ |
83 | 84 | this->hSession = nullptr; |
84 | 85 | } |
85 | 86 | |
86 | - void Local::Session::wait(time_t timeout) { | |
87 | + void Local::Session::chkResponse(int rc) { | |
87 | 88 | |
88 | - std::lock_guard<std::mutex> lock(sync); | |
89 | + if(rc == 0) | |
90 | + return; | |
89 | 91 | |
90 | - int rc = lib3270_wait_for_ready(this->hSession, timeout); | |
92 | +#ifdef _WIN32 | |
93 | + if(rc == ENOTCONN) | |
94 | + throw std::runtime_error("Not connected"); | |
95 | +#endif // _WIN32 | |
91 | 96 | |
92 | - if(rc) { | |
93 | - throw std::system_error(rc, std::system_category()); | |
94 | - } | |
97 | + throw std::system_error(rc, std::system_category()); | |
95 | 98 | |
96 | 99 | } |
97 | 100 | |
98 | - void Local::Session::connect(const char *url) { | |
101 | + void Local::Session::wait(time_t timeout) { | |
102 | + | |
99 | 103 | std::lock_guard<std::mutex> lock(sync); |
100 | - int rc = lib3270_connect_url(hSession,url,0); | |
104 | + chkResponse(lib3270_wait(this->hSession, timeout)); | |
101 | 105 | |
102 | - if(rc) { | |
103 | - throw std::system_error(rc, std::system_category()); | |
104 | - } | |
106 | + } | |
105 | 107 | |
108 | + void Local::Session::connect(const char *url) { | |
109 | + std::lock_guard<std::mutex> lock(sync); | |
110 | + chkResponse(lib3270_connect_url(hSession,url,0)); | |
106 | 111 | } |
107 | 112 | |
108 | 113 | void Local::Session::disconnect() { |
... | ... | @@ -112,7 +117,8 @@ |
112 | 117 | |
113 | 118 | // Wait for session state. |
114 | 119 | void Local::Session::waitForReady(time_t timeout) throw() { |
115 | - this->wait(timeout); | |
120 | + std::lock_guard<std::mutex> lock(sync); | |
121 | + chkResponse(lib3270_wait_for_ready(hSession,timeout)); | |
116 | 122 | } |
117 | 123 | |
118 | 124 | std::string Local::Session::toString(int baddr, size_t len, char lf) const { |
... | ... | @@ -231,10 +237,7 @@ |
231 | 237 | |
232 | 238 | string converted = convertToHost(text); |
233 | 239 | |
234 | - int rc = lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size()); | |
235 | - if(rc) { | |
236 | - throw std::system_error(errno, std::system_category()); | |
237 | - } | |
240 | + chkResponse(lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size())); | |
238 | 241 | |
239 | 242 | return *this; |
240 | 243 | } |
... | ... | @@ -244,10 +247,7 @@ |
244 | 247 | |
245 | 248 | string converted = convertToHost(text,length); |
246 | 249 | |
247 | - int rc = lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size()); | |
248 | - if(rc) { | |
249 | - throw std::system_error(errno, std::system_category()); | |
250 | - } | |
250 | + chkResponse(lib3270_input_string(this->hSession, (unsigned char *) converted.c_str(), converted.size())); | |
251 | 251 | |
252 | 252 | return *this; |
253 | 253 | } |
... | ... | @@ -316,11 +316,7 @@ |
316 | 316 | |
317 | 317 | std::lock_guard<std::mutex> lock(sync); |
318 | 318 | |
319 | - int rc = actions[(size_t) action](hSession); | |
320 | - | |
321 | - if(rc) { | |
322 | - throw std::system_error(errno, std::system_category()); | |
323 | - } | |
319 | + chkResponse(actions[(size_t) action](hSession)); | |
324 | 320 | |
325 | 321 | return *this; |
326 | 322 | } |
... | ... | @@ -329,10 +325,7 @@ |
329 | 325 | |
330 | 326 | std::lock_guard<std::mutex> lock(sync); |
331 | 327 | |
332 | - int rc = lib3270_pfkey(hSession,(int) value); | |
333 | - if(rc) { | |
334 | - throw std::system_error(errno, std::system_category()); | |
335 | - } | |
328 | + chkResponse(lib3270_pfkey(hSession,(int) value)); | |
336 | 329 | |
337 | 330 | return *this; |
338 | 331 | } |
... | ... | @@ -341,10 +334,7 @@ |
341 | 334 | |
342 | 335 | std::lock_guard<std::mutex> lock(sync); |
343 | 336 | |
344 | - int rc = lib3270_pakey(hSession,(int) value); | |
345 | - if(rc) { | |
346 | - throw std::system_error(errno, std::system_category()); | |
347 | - } | |
337 | + chkResponse(lib3270_pakey(hSession,(int) value)); | |
348 | 338 | |
349 | 339 | return *this; |
350 | 340 | } |
... | ... | @@ -469,22 +459,20 @@ |
469 | 459 | /// @brief Execute action by name. |
470 | 460 | TN3270::Session & Local::Session::action(const char *action_name) { |
471 | 461 | |
472 | - if(lib3270_action(hSession,action_name)) { | |
473 | - throw std::system_error(errno, std::system_category()); | |
474 | - } | |
462 | + chkResponse(lib3270_action(hSession,action_name)); | |
475 | 463 | |
476 | 464 | return *this; |
477 | 465 | } |
478 | 466 | |
479 | 467 | /// @brief Wait. |
480 | 468 | TN3270::Session & Local::Session::wait(unsigned short seconds) { |
481 | - | |
469 | + chkResponse(lib3270_wait(hSession,seconds)); | |
482 | 470 | return *this; |
483 | 471 | } |
484 | 472 | |
485 | 473 | /// @brief Wait for update. |
486 | 474 | TN3270::Session & Local::Session::wait_for_update(unsigned short seconds) { |
487 | - | |
475 | + throw std::system_error(ENOTSUP, std::system_category()); | |
488 | 476 | return *this; |
489 | 477 | } |
490 | 478 | ... | ... |
client/src/testprogram/testprogram.cc
... | ... | @@ -81,6 +81,8 @@ |
81 | 81 | << "\tRevision: " << host.getRevision() |
82 | 82 | << std::endl; |
83 | 83 | |
84 | + host.connect(); | |
85 | + | |
84 | 86 | cout |
85 | 87 | << "Connection state is " << toCharString(host.getConnectionState()) << std::endl |
86 | 88 | << "Program message is " << toCharString(host.getProgramMessage()) << std::endl | ... | ... |
common/src/include/lib3270/ipc.h
... | ... | @@ -366,7 +366,7 @@ |
366 | 366 | return session->getConnectionState() == state; |
367 | 367 | } |
368 | 368 | |
369 | - Host & connect(const char *url, bool sync = true); | |
369 | + Host & connect(const char *url = nullptr, bool sync = true); | |
370 | 370 | Host & disconnect(); |
371 | 371 | |
372 | 372 | Host & waitForReady(time_t timeout = DEFAULT_TIMEOUT); | ... | ... |