Commit 0668e0fac6edd49e03e6371756acc3c7a2e02274

Authored by Perry Werneck
1 parent 17909801
Exists in master and in 1 other branch develop

Fixing issues on non GUI (local) sessions.

client/src/core/constants.cc
@@ -104,7 +104,7 @@ TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMess @@ -104,7 +104,7 @@ TN3270_PUBLIC const char * toCharString(const TN3270::ProgramMessage programMess
104 "", 104 "",
105 "X System", 105 "X System",
106 "X Wait", 106 "X Wait",
107 - "Connected" 107 + "Connected",
108 "X Not Connected", 108 "X Not Connected",
109 "Awaiting first", 109 "Awaiting first",
110 "X -f", 110 "X -f",
client/src/host/init.cc
@@ -42,15 +42,23 @@ @@ -42,15 +42,23 @@
42 42
43 TN3270::Host::Host(const char *id, const char *charset) { 43 TN3270::Host::Host(const char *id, const char *charset) {
44 44
45 - debug("Creating host id=\"", id); 45 + if(!id)
  46 + id = "";
  47 +
  48 + debug("Creating host id=\"", id, "\"");
46 49
47 this->timeout = 5; 50 this->timeout = 5;
48 this->session = Session::getInstance(id, charset); 51 this->session = Session::getInstance(id, charset);
49 52
  53 + debug("Create host with session ",this->session);
  54 +
50 } 55 }
51 56
52 57
53 TN3270::Host::~Host() { 58 TN3270::Host::~Host() {
54 - delete this->session;  
55 - this->session = nullptr; 59 + debug("Deleting host session ",this->session);
  60 + if(this->session) {
  61 + delete this->session;
  62 + this->session = nullptr;
  63 + }
56 } 64 }
client/src/host/properties.cc
@@ -60,7 +60,7 @@ std::vector<TN3270::Attribute> TN3270::Host::getAttributes() const { @@ -60,7 +60,7 @@ std::vector<TN3270::Attribute> TN3270::Host::getAttributes() const {
60 60
61 void TN3270::Host::setTimeout(time_t timeout) noexcept { 61 void TN3270::Host::setTimeout(time_t timeout) noexcept {
62 this->timeout = timeout; 62 this->timeout = timeout;
63 - this->session->setWaitMode(timeout != 0); 63 + this->session->setTimeout(timeout);
64 } 64 }
65 65
66 66
client/src/include/lib3270/ipc.h
@@ -569,7 +569,7 @@ @@ -569,7 +569,7 @@
569 virtual void setHostURL(const char *url) = 0; 569 virtual void setHostURL(const char *url) = 0;
570 570
571 virtual void setUnlockDelay(unsigned short delay = 350) = 0; 571 virtual void setUnlockDelay(unsigned short delay = 350) = 0;
572 - virtual void setWaitMode(bool mode) = 0; 572 + virtual void setTimeout(time_t timeout = 0) = 0;
573 virtual void setLockOnOperatorError(bool lock = true) = 0; 573 virtual void setLockOnOperatorError(bool lock = true) = 0;
574 574
575 virtual unsigned short getScreenWidth() const = 0; 575 virtual unsigned short getScreenWidth() const = 0;
@@ -668,6 +668,9 @@ @@ -668,6 +668,9 @@
668 int overflow(int c) override; 668 int overflow(int c) override;
669 669
670 public: 670 public:
  671 + Host(const Host &src) = delete;
  672 + Host(const Host *src) = delete;
  673 +
671 Host(const char *id, const char *charset = nullptr); 674 Host(const char *id, const char *charset = nullptr);
672 675
673 ~Host(); 676 ~Host();
client/src/session/local/actions.cc
@@ -50,56 +50,63 @@ @@ -50,56 +50,63 @@
50 } 50 }
51 51
52 bool Local::Action::activatable() const noexcept { 52 bool Local::Action::activatable() const noexcept {
53 - std::lock_guard<std::mutex> lock(this->session->sync); 53 + std::lock_guard<std::recursive_mutex> lock(this->session->sync);
54 debug(__FUNCTION__,"(",(void *) descriptor,")"); 54 debug(__FUNCTION__,"(",(void *) descriptor,")");
55 return lib3270_action_is_activatable(this->descriptor,this->session->hSession); 55 return lib3270_action_is_activatable(this->descriptor,this->session->hSession);
56 } 56 }
57 57
58 void Local::Action::activate() { 58 void Local::Action::activate() {
59 - std::lock_guard<std::mutex> lock(this->session->sync); 59 + std::lock_guard<std::recursive_mutex> lock(this->session->sync);
60 60
61 chkResponse(lib3270_action_activate(this->descriptor,this->session->hSession)); 61 chkResponse(lib3270_action_activate(this->descriptor,this->session->hSession));
62 62
63 } 63 }
64 64
65 void Local::Action::wait(time_t seconds) { 65 void Local::Action::wait(time_t seconds) {
66 - std::lock_guard<std::mutex> lock(this->session->sync); 66 + std::lock_guard<std::recursive_mutex> lock(this->session->sync);
67 chkResponse(lib3270_wait_for_ready(this->session->hSession,seconds)); 67 chkResponse(lib3270_wait_for_ready(this->session->hSession,seconds));
68 } 68 }
69 69
70 TN3270::Action * Local::Session::getAction(const LIB3270_ACTION *descriptor) { 70 TN3270::Action * Local::Session::getAction(const LIB3270_ACTION *descriptor) {
71 - std::lock_guard<std::mutex> lock(sync); 71 + std::lock_guard<std::recursive_mutex> lock(sync);
72 return new Local::Action(this, descriptor); 72 return new Local::Action(this, descriptor);
73 } 73 }
74 74
75 void Local::Session::action(const char *action_name) { 75 void Local::Session::action(const char *action_name) {
76 - std::lock_guard<std::mutex> lock(sync); 76 + std::lock_guard<std::recursive_mutex> lock(sync);
77 chkResponse(lib3270_action_activate_by_name(action_name,hSession)); 77 chkResponse(lib3270_action_activate_by_name(action_name,hSession));
  78 + if(this->timeout)
  79 + chkResponse(lib3270_wait_for_ready(hSession,this->timeout));
78 } 80 }
79 81
80 void Local::Session::connect(const char *url, time_t seconds) { 82 void Local::Session::connect(const char *url, time_t seconds) {
81 83
82 - std::lock_guard<std::mutex> lock(sync);  
83 - chkResponse(lib3270_connect_url(hSession,url,seconds)); 84 + std::lock_guard<std::recursive_mutex> lock(sync);
  85 + chkResponse(lib3270_connect_url(hSession,url,seconds ? seconds : this->timeout));
  86 +
84 } 87 }
85 88
86 void Local::Session::disconnect() { 89 void Local::Session::disconnect() {
87 90
88 - std::lock_guard<std::mutex> lock(sync); 91 + std::lock_guard<std::recursive_mutex> lock(sync);
89 chkResponse(lib3270_disconnect(hSession)); 92 chkResponse(lib3270_disconnect(hSession));
90 } 93 }
91 94
92 void Local::Session::pfkey(unsigned short value) { 95 void Local::Session::pfkey(unsigned short value) {
93 96
94 - std::lock_guard<std::mutex> lock(sync); 97 + std::lock_guard<std::recursive_mutex> lock(sync);
95 chkResponse(lib3270_pfkey(hSession,value)); 98 chkResponse(lib3270_pfkey(hSession,value));
  99 + if(this->timeout)
  100 + chkResponse(lib3270_wait_for_ready(hSession,this->timeout));
96 101
97 } 102 }
98 103
99 void Local::Session::pakey(unsigned short value) { 104 void Local::Session::pakey(unsigned short value) {
100 105
101 - std::lock_guard<std::mutex> lock(sync); 106 + std::lock_guard<std::recursive_mutex> lock(sync);
102 chkResponse(lib3270_pakey(hSession,value)); 107 chkResponse(lib3270_pakey(hSession,value));
  108 + if(this->timeout)
  109 + chkResponse(lib3270_wait_for_ready(hSession,this->timeout));
103 110
104 } 111 }
105 112
@@ -142,14 +149,16 @@ @@ -142,14 +149,16 @@
142 throw std::system_error(EINVAL, std::system_category()); 149 throw std::system_error(EINVAL, std::system_category());
143 } 150 }
144 151
145 - std::lock_guard<std::mutex> lock(sync); 152 + std::lock_guard<std::recursive_mutex> lock(sync);
146 chkResponse(actions[(size_t) action](hSession)); 153 chkResponse(actions[(size_t) action](hSession));
  154 + if(this->timeout)
  155 + chkResponse(lib3270_wait_for_ready(hSession,this->timeout));
147 156
148 } 157 }
149 158
150 void Local::Session::print(LIB3270_CONTENT_OPTION option) { 159 void Local::Session::print(LIB3270_CONTENT_OPTION option) {
151 160
152 - std::lock_guard<std::mutex> lock(sync); 161 + std::lock_guard<std::recursive_mutex> lock(sync);
153 162
154 switch(option) { 163 switch(option) {
155 case LIB3270_CONTENT_ALL: 164 case LIB3270_CONTENT_ALL:
client/src/session/local/attribute.cc
@@ -345,7 +345,7 @@ @@ -345,7 +345,7 @@
345 345
346 Attribute Local::Session::getAttribute(const char *name) const { 346 Attribute Local::Session::getAttribute(const char *name) const {
347 347
348 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 348 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
349 349
350 // Check for integer properties. 350 // Check for integer properties.
351 { 351 {
@@ -415,7 +415,7 @@ @@ -415,7 +415,7 @@
415 415
416 void Local::Session::getAttributes(std::vector<Attribute> & attributes) const { 416 void Local::Session::getAttributes(std::vector<Attribute> & attributes) const {
417 417
418 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 418 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
419 419
420 // Add integer properties. 420 // Add integer properties.
421 { 421 {
@@ -465,37 +465,37 @@ @@ -465,37 +465,37 @@
465 } 465 }
466 466
467 unsigned short Local::Session::getScreenWidth() const { 467 unsigned short Local::Session::getScreenWidth() const {
468 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 468 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
469 return (unsigned short) lib3270_get_width(hSession); 469 return (unsigned short) lib3270_get_width(hSession);
470 } 470 }
471 471
472 unsigned short Local::Session::getScreenHeight() const { 472 unsigned short Local::Session::getScreenHeight() const {
473 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 473 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
474 return (unsigned short) lib3270_get_height(hSession); 474 return (unsigned short) lib3270_get_height(hSession);
475 } 475 }
476 476
477 unsigned short Local::Session::getScreenLength() const { 477 unsigned short Local::Session::getScreenLength() const {
478 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 478 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
479 return (unsigned short) lib3270_get_length(hSession); 479 return (unsigned short) lib3270_get_length(hSession);
480 } 480 }
481 481
482 void Local::Session::setUnlockDelay(unsigned short delay) { 482 void Local::Session::setUnlockDelay(unsigned short delay) {
483 - std::lock_guard<std::mutex> lock(sync); 483 + std::lock_guard<std::recursive_mutex> lock(sync);
484 chkResponse(lib3270_set_unlock_delay(hSession,delay)); 484 chkResponse(lib3270_set_unlock_delay(hSession,delay));
485 } 485 }
486 486
487 - void Local::Session::setWaitMode(bool mode) {  
488 - std::lock_guard<std::mutex> lock(sync);  
489 - chkResponse(ENOTSUP); 487 + void Local::Session::setTimeout(time_t timeout) {
  488 + std::lock_guard<std::recursive_mutex> lock(sync);
  489 + this->timeout = timeout;
490 } 490 }
491 491
492 void Local::Session::setLockOnOperatorError(bool lock) { 492 void Local::Session::setLockOnOperatorError(bool lock) {
493 - std::lock_guard<std::mutex> guard(sync); 493 + std::lock_guard<std::recursive_mutex> guard(sync);
494 chkResponse(lib3270_set_lock_on_operator_error(hSession,lock ? 1 : 0)); 494 chkResponse(lib3270_set_lock_on_operator_error(hSession,lock ? 1 : 0));
495 } 495 }
496 496
497 unsigned short Local::Session::setCursor(int addr) { 497 unsigned short Local::Session::setCursor(int addr) {
498 - std::lock_guard<std::mutex> lock(sync); 498 + std::lock_guard<std::recursive_mutex> lock(sync);
499 499
500 int rc = lib3270_set_cursor_address(hSession,addr); 500 int rc = lib3270_set_cursor_address(hSession,addr);
501 if(rc < 0) 501 if(rc < 0)
@@ -506,7 +506,7 @@ @@ -506,7 +506,7 @@
506 } 506 }
507 507
508 unsigned short Local::Session::setCursor(unsigned short row, unsigned short col) { 508 unsigned short Local::Session::setCursor(unsigned short row, unsigned short col) {
509 - std::lock_guard<std::mutex> lock(sync); 509 + std::lock_guard<std::recursive_mutex> lock(sync);
510 510
511 int rc = lib3270_set_cursor_position(hSession,row,col); 511 int rc = lib3270_set_cursor_position(hSession,row,col);
512 if(rc < 0) 512 if(rc < 0)
@@ -517,7 +517,7 @@ @@ -517,7 +517,7 @@
517 } 517 }
518 518
519 unsigned short Local::Session::getCursorAddress() { 519 unsigned short Local::Session::getCursorAddress() {
520 - std::lock_guard<std::mutex> lock(sync); 520 + std::lock_guard<std::recursive_mutex> lock(sync);
521 521
522 int rc = lib3270_get_cursor_address(hSession); 522 int rc = lib3270_get_cursor_address(hSession);
523 523
@@ -529,35 +529,36 @@ @@ -529,35 +529,36 @@
529 529
530 std::string Local::Session::getVersion() const { 530 std::string Local::Session::getVersion() const {
531 531
532 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 532 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
533 return lib3270_get_version(); 533 return lib3270_get_version();
534 534
535 } 535 }
536 536
537 std::string Local::Session::getRevision() const { 537 std::string Local::Session::getRevision() const {
538 538
539 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 539 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
540 return lib3270_get_revision(); 540 return lib3270_get_revision();
541 541
542 } 542 }
543 543
544 std::string Local::Session::getAssociatedLUName() const { 544 std::string Local::Session::getAssociatedLUName() const {
545 545
546 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync);  
547 - return lib3270_get_associated_luname(hSession); 546 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
  547 + const char * luname = lib3270_get_associated_luname(hSession);
  548 + return string(luname ? luname : "");
548 549
549 } 550 }
550 551
551 std::string Local::Session::getHostURL() const { 552 std::string Local::Session::getHostURL() const {
552 553
553 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 554 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
554 return lib3270_get_url(hSession); 555 return lib3270_get_url(hSession);
555 556
556 } 557 }
557 558
558 void Local::Session::setHostURL(const char *url) { 559 void Local::Session::setHostURL(const char *url) {
559 560
560 - std::lock_guard<std::mutex> lock(sync); 561 + std::lock_guard<std::recursive_mutex> lock(sync);
561 chkResponse(lib3270_set_url(hSession, url)); 562 chkResponse(lib3270_set_url(hSession, url));
562 563
563 } 564 }
client/src/session/local/get.cc
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 44
45 std::string Local::Session::get() const { 45 std::string Local::Session::get() const {
46 46
47 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 47 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
48 48
49 lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, 0, -1, '\n'); 49 lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, 0, -1, '\n');
50 50
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 57
58 std::string Local::Session::get(int baddr, int len, char lf) const { 58 std::string Local::Session::get(int baddr, int len, char lf) const {
59 59
60 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 60 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
61 61
62 lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, baddr, len, lf); 62 lib3270_auto_cleanup<char> text = lib3270_get_string_at_address(hSession, baddr, len, lf);
63 63
@@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
70 70
71 std::string Local::Session::get(unsigned int row, unsigned int col, int len, char lf) const { 71 std::string Local::Session::get(unsigned int row, unsigned int col, int len, char lf) const {
72 72
73 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 73 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
74 74
75 lib3270_auto_cleanup<char> text = lib3270_get_string_at(hSession, row, col, len, lf); 75 lib3270_auto_cleanup<char> text = lib3270_get_string_at(hSession, row, col, len, lf);
76 76
@@ -84,27 +84,28 @@ @@ -84,27 +84,28 @@
84 84
85 ProgramMessage Local::Session::getProgramMessage() const { 85 ProgramMessage Local::Session::getProgramMessage() const {
86 86
87 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 87 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
88 return (ProgramMessage) lib3270_get_program_message(this->hSession); 88 return (ProgramMessage) lib3270_get_program_message(this->hSession);
89 89
90 } 90 }
91 91
92 ConnectionState Local::Session::getConnectionState() const { 92 ConnectionState Local::Session::getConnectionState() const {
93 93
94 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 94 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
95 return (ConnectionState) lib3270_get_connection_state(this->hSession); 95 return (ConnectionState) lib3270_get_connection_state(this->hSession);
96 96
97 } 97 }
98 98
99 SSLState Local::Session::getSSLState() const { 99 SSLState Local::Session::getSSLState() const {
100 100
101 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 101 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
102 return (TN3270::SSLState) lib3270_get_ssl_state(hSession); 102 return (TN3270::SSLState) lib3270_get_ssl_state(hSession);
103 103
104 } 104 }
105 105
106 LIB3270_KEYBOARD_LOCK_STATE Local::Session::getKeyboardLockState() const { 106 LIB3270_KEYBOARD_LOCK_STATE Local::Session::getKeyboardLockState() const {
107 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 107 +
  108 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
108 return lib3270_get_keyboard_lock_state(hSession); 109 return lib3270_get_keyboard_lock_state(hSession);
109 } 110 }
110 111
client/src/session/local/init.cc
@@ -61,9 +61,10 @@ @@ -61,9 +61,10 @@
61 61
62 Local::Session::Session(const char *charset) : Abstract::Session() { 62 Local::Session::Session(const char *charset) : Abstract::Session() {
63 63
64 - std::lock_guard<std::mutex> lock(sync); 64 + std::lock_guard<std::recursive_mutex> lock(sync);
65 65
66 this->hSession = lib3270_session_new(""); 66 this->hSession = lib3270_session_new("");
  67 + this->timeout = 5;
67 68
68 lib3270_set_user_data(this->hSession,(void *) this); 69 lib3270_set_user_data(this->hSession,(void *) this);
69 70
@@ -99,7 +100,7 @@ @@ -99,7 +100,7 @@
99 100
100 Local::Session::~Session() { 101 Local::Session::~Session() {
101 102
102 - std::lock_guard<std::mutex> lock(sync); 103 + std::lock_guard<std::recursive_mutex> lock(sync);
103 104
104 lib3270_session_free(this->hSession); 105 lib3270_session_free(this->hSession);
105 this->hSession = nullptr; 106 this->hSession = nullptr;
client/src/session/local/private.h
@@ -77,11 +77,14 @@ @@ -77,11 +77,14 @@
77 77
78 friend class Action; 78 friend class Action;
79 79
  80 + /// @brief Timeout for automatic waits.
  81 + time_t timeout;
  82 +
80 /// @brief Handle of the related instance of lib3270 83 /// @brief Handle of the related instance of lib3270
81 H3270 * hSession; 84 H3270 * hSession;
82 85
83 - /// @brief Mutex to serialize access to lib3270  
84 - std::mutex sync; 86 + /// @brief Recursive mutex to serialize access to lib3270
  87 + std::recursive_mutex sync;
85 88
86 /// @brief Popup Handler. 89 /// @brief Popup Handler.
87 static int popupHandler(H3270 *session, const LIB3270_POPUP *popup, unsigned char wait); 90 static int popupHandler(H3270 *session, const LIB3270_POPUP *popup, unsigned char wait);
@@ -152,7 +155,7 @@ @@ -152,7 +155,7 @@
152 unsigned short getScreenHeight() const override; 155 unsigned short getScreenHeight() const override;
153 unsigned short getScreenLength() const override; 156 unsigned short getScreenLength() const override;
154 void setUnlockDelay(unsigned short delay) override; 157 void setUnlockDelay(unsigned short delay) override;
155 - void setWaitMode(bool mode) override; 158 + void setTimeout(time_t timeout) override;
156 void setLockOnOperatorError(bool lock) override; 159 void setLockOnOperatorError(bool lock) override;
157 void setCharSet(const char *charset = NULL) override; 160 void setCharSet(const char *charset = NULL) override;
158 unsigned short setCursor(int addr) override; 161 unsigned short setCursor(int addr) override;
client/src/session/local/set.cc
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 44
45 void Local::Session::set(const std::string &str) { 45 void Local::Session::set(const std::string &str) {
46 46
47 - std::lock_guard<std::mutex> lock(this->sync); 47 + std::lock_guard<std::recursive_mutex> lock(this->sync);
48 48
49 int rc = lib3270_set_field(hSession,str.c_str(),str.length()); 49 int rc = lib3270_set_field(hSession,str.c_str(),str.length());
50 if(rc < 0) 50 if(rc < 0)
@@ -54,7 +54,7 @@ @@ -54,7 +54,7 @@
54 54
55 void Local::Session::set(int baddr, const std::string &str) { 55 void Local::Session::set(int baddr, const std::string &str) {
56 56
57 - std::lock_guard<std::mutex> lock(this->sync); 57 + std::lock_guard<std::recursive_mutex> lock(this->sync);
58 58
59 int rc = lib3270_set_string_at_address(hSession,baddr,(unsigned char *) str.c_str(),str.length()); 59 int rc = lib3270_set_string_at_address(hSession,baddr,(unsigned char *) str.c_str(),str.length());
60 if(rc < 0) 60 if(rc < 0)
@@ -64,7 +64,7 @@ @@ -64,7 +64,7 @@
64 64
65 void Local::Session::set(int row, int col, const std::string &str) { 65 void Local::Session::set(int row, int col, const std::string &str) {
66 66
67 - std::lock_guard<std::mutex> lock(this->sync); 67 + std::lock_guard<std::recursive_mutex> lock(this->sync);
68 68
69 int rc = lib3270_set_string_at(hSession,row,col,(unsigned char *) str.c_str(),str.length()); 69 int rc = lib3270_set_string_at(hSession,row,col,(unsigned char *) str.c_str(),str.length());
70 if(rc < 0) 70 if(rc < 0)
client/src/session/local/wait.cc
@@ -45,53 +45,53 @@ @@ -45,53 +45,53 @@
45 45
46 void Local::Session::wait(time_t seconds) const { 46 void Local::Session::wait(time_t seconds) const {
47 47
48 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 48 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
49 chkResponse(lib3270_wait(this->hSession, seconds)); 49 chkResponse(lib3270_wait(this->hSession, seconds));
50 50
51 } 51 }
52 52
53 void Local::Session::waitForReady(time_t timeout) const { 53 void Local::Session::waitForReady(time_t timeout) const {
54 54
55 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 55 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
56 chkResponse(lib3270_wait_for_ready(this->hSession, timeout)); 56 chkResponse(lib3270_wait_for_ready(this->hSession, timeout));
57 } 57 }
58 58
59 void Local::Session::waitForConnectionState(ConnectionState state, time_t timeout) const { 59 void Local::Session::waitForConnectionState(ConnectionState state, time_t timeout) const {
60 60
61 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 61 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
62 chkResponse(lib3270_wait_for_cstate(this->hSession, (LIB3270_CSTATE) state, timeout)); 62 chkResponse(lib3270_wait_for_cstate(this->hSession, (LIB3270_CSTATE) state, timeout));
63 } 63 }
64 64
65 LIB3270_KEYBOARD_LOCK_STATE Local::Session::waitForKeyboardUnlock(time_t timeout) const { 65 LIB3270_KEYBOARD_LOCK_STATE Local::Session::waitForKeyboardUnlock(time_t timeout) const {
66 66
67 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 67 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
68 return lib3270_wait_for_keyboard_unlock(this->hSession, timeout); 68 return lib3270_wait_for_keyboard_unlock(this->hSession, timeout);
69 } 69 }
70 70
71 void Local::Session::waitForChange(time_t seconds) const { 71 void Local::Session::waitForChange(time_t seconds) const {
72 72
73 - std::lock_guard<std::mutex> lock(const_cast<Local::Session *>(this)->sync); 73 + std::lock_guard<std::recursive_mutex> lock(const_cast<Local::Session *>(this)->sync);
74 chkResponse(lib3270_wait_for_update(this->hSession, seconds)); 74 chkResponse(lib3270_wait_for_update(this->hSession, seconds));
75 75
76 } 76 }
77 77
78 void Local::Session::wait(const char *text, int seconds) { 78 void Local::Session::wait(const char *text, int seconds) {
79 79
80 - std::lock_guard<std::mutex> lock(sync); 80 + std::lock_guard<std::recursive_mutex> lock(sync);
81 chkResponse(lib3270_wait_for_string(hSession,convertToHost(text,-1).c_str(),seconds)); 81 chkResponse(lib3270_wait_for_string(hSession,convertToHost(text,-1).c_str(),seconds));
82 82
83 } 83 }
84 84
85 void Local::Session::wait(unsigned short row, unsigned short col, const char *text, int seconds) { 85 void Local::Session::wait(unsigned short row, unsigned short col, const char *text, int seconds) {
86 86
87 - std::lock_guard<std::mutex> lock(sync); 87 + std::lock_guard<std::recursive_mutex> lock(sync);
88 chkResponse(lib3270_wait_for_string_at(hSession,row,col,convertToHost(text,-1).c_str(),seconds)); 88 chkResponse(lib3270_wait_for_string_at(hSession,row,col,convertToHost(text,-1).c_str(),seconds));
89 89
90 } 90 }
91 91
92 void Local::Session::wait(int addr, const char *text, int seconds) { 92 void Local::Session::wait(int addr, const char *text, int seconds) {
93 93
94 - std::lock_guard<std::mutex> lock(sync); 94 + std::lock_guard<std::recursive_mutex> lock(sync);
95 chkResponse(lib3270_wait_for_string_at_address(hSession,addr,convertToHost(text,-1).c_str(),seconds)); 95 chkResponse(lib3270_wait_for_string_at_address(hSession,addr,convertToHost(text,-1).c_str(),seconds));
96 96
97 } 97 }
client/src/session/remote/private.h
@@ -160,7 +160,7 @@ @@ -160,7 +160,7 @@
160 unsigned short getScreenHeight() const override; 160 unsigned short getScreenHeight() const override;
161 unsigned short getScreenLength() const override; 161 unsigned short getScreenLength() const override;
162 void setUnlockDelay(unsigned short delay) override; 162 void setUnlockDelay(unsigned short delay) override;
163 - void setWaitMode(bool mode) override; 163 + void setTimeout(time_t timeout) override;
164 void setLockOnOperatorError(bool lock) override; 164 void setLockOnOperatorError(bool lock) override;
165 void setCharSet(const char *charset = NULL) override; 165 void setCharSet(const char *charset = NULL) override;
166 unsigned short setCursor(int addr) override; 166 unsigned short setCursor(int addr) override;
client/src/session/remote/properties.cc
@@ -160,12 +160,12 @@ @@ -160,12 +160,12 @@
160 160
161 } 161 }
162 162
163 - void IPC::Session::setWaitMode(bool mode) { 163 + void IPC::Session::setTimeout(time_t timeout) {
164 164
165 int32_t rc; 165 int32_t rc;
166 166
167 Request(*this,"setWaitMode") 167 Request(*this,"setWaitMode")
168 - .push(mode) 168 + .push(timeout != 0)
169 .call() 169 .call()
170 .pop(rc); 170 .pop(rc);
171 171
client/src/session/tools.cc
@@ -44,6 +44,8 @@ @@ -44,6 +44,8 @@
44 44
45 void chkResponse(int rc) { 45 void chkResponse(int rc) {
46 46
  47 + debug("rc=",rc);
  48 +
47 if(rc == 0) 49 if(rc == 0)
48 return; 50 return;
49 51
client/src/testprogram/testprogram.cc
@@ -98,7 +98,7 @@ @@ -98,7 +98,7 @@
98 */ 98 */
99 99
100 // Test Attributes 100 // Test Attributes
101 - static void testAttributes(const char *session) { 101 + static void testAttributes(const char *session, const char *url) {
102 102
103 TN3270::Host host{session}; 103 TN3270::Host host{session};
104 104
@@ -122,7 +122,7 @@ @@ -122,7 +122,7 @@
122 } 122 }
123 123
124 // Performance test. 124 // Performance test.
125 - static void testPerformance(const char *session) { 125 + static void testPerformance(const char *session, const char *url) {
126 126
127 try { 127 try {
128 128
@@ -165,30 +165,22 @@ @@ -165,30 +165,22 @@
165 } 165 }
166 166
167 // test host object 167 // test host object
168 - static void testHost(const char *session) { 168 + static void testHost(const char *session, const char *url) {
169 169
170 try { 170 try {
171 171
172 TN3270::Host host{session}; 172 TN3270::Host host{session};
173 173
174 - host.setTimeout(10);  
175 -  
176 - host.connect();  
177 - host.push(TN3270::ENTER);  
178 -  
179 - host.toString(14,1,75,0);  
180 -  
181 - // host.disconnect();  
182 -  
183 - /*  
184 cout 174 cout
185 << "Version: " << host["version"] 175 << "Version: " << host["version"]
186 << "\tRevision: " << host["Revision"] 176 << "\tRevision: " << host["Revision"]
187 << "\tConnected: " << host["Connected"] 177 << "\tConnected: " << host["Connected"]
188 << std::endl; 178 << std::endl;
189 179
190 - host.setUnlockDelay(0);  
191 - host.connect(nullptr); 180 + host.setUnlockDelay(0); // Disable the 350ms delay on screen changes.
  181 + host.setTimeout(10); // Set the default timeout.
  182 + host["crlget"] = false; // Disable CRL get to speed up the connection.
  183 + host.connect(url);
192 184
193 cout 185 cout
194 << "Wait for unlock returns " << host.getKeyboardLockState() << std::endl 186 << "Wait for unlock returns " << host.getKeyboardLockState() << std::endl
@@ -203,28 +195,30 @@ @@ -203,28 +195,30 @@
203 } 195 }
204 196
205 host.setCursor(10,10); 197 host.setCursor(10,10);
206 -  
207 - host.wait(10);  
208 - 198 +// host.wait(10);
209 // host.input("test@0another line"); 199 // host.input("test@0another line");
210 200
  201 + cout << "Sending ENTER" << endl;
211 host.push(TN3270::ENTER); 202 host.push(TN3270::ENTER);
212 - host.wait(10); 203 + cout << "ENTER returns" << endl;
  204 +
  205 + host.wait(2);
213 206
214 cout << host << endl; 207 cout << host << endl;
215 208
216 cout << endl << "[" << host.toString((unsigned int) 1, (unsigned int) 3,7) << "]" << endl; 209 cout << endl << "[" << host.toString((unsigned int) 1, (unsigned int) 3,7) << "]" << endl;
217 cout << endl << "[" << host.toString((int) 15, (int) 10) << "]" << endl; 210 cout << endl << "[" << host.toString((int) 15, (int) 10) << "]" << endl;
218 211
  212 + cout << "Sending PF3" << endl;
219 host.pfkey(3); 213 host.pfkey(3);
220 - host.wait(10); 214 + cout << "PF3 returns" << endl;
221 215
222 cout << host << endl; 216 cout << host << endl;
223 - host.wait(10);  
224 217
  218 + cout << "Disconnecting" << endl;
225 host.disconnect(); 219 host.disconnect();
226 220
227 - */ 221 + cout << "Test complete" << endl;
228 222
229 } catch(const std::exception &e) { 223 } catch(const std::exception &e) {
230 224
@@ -237,10 +231,13 @@ @@ -237,10 +231,13 @@
237 int main(int argc, char **argv) { 231 int main(int argc, char **argv) {
238 232
239 const char * session = ":A"; 233 const char * session = ":A";
  234 + const char * url = nullptr;
240 235
241 static struct option options[] = { 236 static struct option options[] = {
242 { "session", required_argument, 0, 's' }, 237 { "session", required_argument, 0, 's' },
  238 + { "url", required_argument, 0, 'U' },
243 { "perftest", no_argument, 0, 'P' }, 239 { "perftest", no_argument, 0, 'P' },
  240 + { "info", no_argument, 0, 'I' },
244 { 0, 0, 0, 0} 241 { 0, 0, 0, 0}
245 242
246 }; 243 };
@@ -252,19 +249,42 @@ @@ -252,19 +249,42 @@
252 switch(opt) { 249 switch(opt) {
253 case 's': 250 case 's':
254 session = optarg; 251 session = optarg;
  252 + cout << "Session: " << session << endl;
  253 + break;
  254 +
  255 + case 'U':
  256 + url = optarg;
  257 + cout << "URL: " << session << endl;
255 break; 258 break;
256 259
257 case 'P': 260 case 'P':
258 - testPerformance(session); 261 + testPerformance(session,url);
  262 + return 0;
  263 +
  264 + case 'I':
  265 + testHost(session,url);
259 return 0; 266 return 0;
260 267
261 } 268 }
262 269
263 } 270 }
264 271
265 - cout << "Session: " << session << endl; 272 + /*
  273 +
  274 + host.setTimeout(10);
  275 +
  276 + host.connect();
  277 + host.push(TN3270::ENTER);
  278 +
  279 + host.toString(14,1,75,0);
  280 +
  281 + // host.disconnect();
  282 + */
  283 +
  284 +
  285 + // cout << "Session: " << session << endl;
266 286
267 - testHost(session); 287 + //testHost(session);
268 // testPerformance(session); 288 // testPerformance(session);
269 289
270 290