Commit 4a2bbf155688742e2155e7987c7bb5116673b5c7

Authored by perry.werneck@gmail.com
1 parent 243e4662

Implementando novo mecanismo de conexao

Showing 4 changed files with 26 additions and 30 deletions   Show diff stats
api.h
... ... @@ -324,8 +324,8 @@
324 324  
325 325 #include <lib3270/actions.h>
326 326  
327   - #define host_connect(n,wait) lib3270_connect(NULL,n,wait)
328   - #define host_reconnect(w) lib3270_reconnect(NULL,w)
  327 + // #define host_connect(n,wait) lib3270_connect(NULL,n,wait)
  328 + // #define host_reconnect(w) lib3270_reconnect(NULL,w)
329 329  
330 330  
331 331 #ifdef __cplusplus
... ...
connect.c
... ... @@ -201,7 +201,7 @@ static void net_connected(H3270 *hSession)
201 201 sockstart(hSession);
202 202 #endif
203 203  
204   - hSession->host.opt = opt;
  204 + hSession->host.opt = opt & ~LIB3270_CONNECT_OPTION_WAIT;
205 205 Replace(hSession->host.current,strdup(hostname));
206 206  
207 207 Replace(hSession->host.full,
... ...
host.c
... ... @@ -457,17 +457,7 @@ static int do_connect(H3270 *hSession)
457 457 return 0;
458 458 }
459 459  
460   -/**
461   - * Connect to selected host.
462   - *
463   - * @param h Session handle.
464   - * @param n Hostname (null to reconnect to the last one;
465   - * @param wait Wait for connection ok before return.
466   - *
467   - * @return 0 if the connection was ok, non zero on error.
468   - *
469   - */
470   -int lib3270_connect(H3270 *hSession, const char *n, int wait)
  460 +int lib3270_connect(H3270 *hSession, int wait)
471 461 {
472 462 int rc;
473 463  
... ... @@ -475,18 +465,18 @@ int lib3270_connect(H3270 *hSession, const char *n, int wait)
475 465  
476 466 lib3270_main_iterate(hSession,0);
477 467  
478   - if(hSession->auto_reconnect_inprogress)
479   - return EAGAIN;
480   -
481   - if(PCONNECTED)
  468 + if (CONNECTED || HALF_CONNECTED)
482 469 return EBUSY;
483 470  
484   - if(n)
485   - lib3270_set_host(hSession,n);
486   -
487 471 if(!hSession->host.full)
488 472 return EINVAL;
489 473  
  474 + if (hSession->auto_reconnect_inprogress)
  475 + return EBUSY;
  476 +
  477 + if(PCONNECTED)
  478 + return EBUSY;
  479 +
490 480 rc = do_connect(hSession);
491 481 if(rc)
492 482 return rc;
... ... @@ -514,7 +504,7 @@ static void try_reconnect(H3270 *session)
514 504 {
515 505 lib3270_write_log(session,"3270","Starting auto-reconnect (Host: %s)",session->host.full ? session->host.full : "-");
516 506 session->auto_reconnect_inprogress = 0;
517   - lib3270_reconnect(session,0);
  507 + lib3270_connect(session,0);
518 508 }
519 509  
520 510 LIB3270_EXPORT int lib3270_disconnect(H3270 *h)
... ... @@ -689,8 +679,6 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
689 679 }
690 680 }
691 681  
692   - trace("SRVC=[%s]",srvc);
693   -
694 682 if(!*hostname)
695 683 return h->host.current;
696 684  
... ... @@ -709,18 +697,22 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n)
709 697 query = "";
710 698 }
711 699  
  700 + trace("SRVC=[%s]",srvc);
  701 +
712 702 Replace(h->host.current,strdup(hostname));
713 703 Replace(h->host.srvc,strdup(srvc));
714 704 Replace(h->host.full,
715 705 lib3270_strdup_printf(
716 706 "%s%s:%s%s%s",
717   - h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "",
  707 + h->host.opt&LIB3270_CONNECT_OPTION_SSL ? "tn3270s://" : "tn3270://",
718 708 hostname,
719 709 srvc,
720 710 *query ? "?" : "",
721 711 query
722 712 ));
723 713  
  714 + trace("hosturl=[%s]",h->host.full);
  715 +
724 716 free(str);
725 717 }
726 718  
... ... @@ -733,6 +725,7 @@ LIB3270_EXPORT const char * lib3270_get_hostname(H3270 *h)
733 725 return h->host.current;
734 726 }
735 727  
  728 +/*
736 729 LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
737 730 {
738 731 int rc;
... ... @@ -742,13 +735,13 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
742 735 if (CONNECTED || HALF_CONNECTED)
743 736 return EBUSY;
744 737  
745   - if (hSession->host.full == CN)
  738 + if (!hSession->host.full)
746 739 return EINVAL;
747 740  
748 741 if (hSession->auto_reconnect_inprogress)
749 742 return EBUSY;
750 743  
751   - rc = lib3270_connect(hSession,hSession->host.full,wait);
  744 + rc = lib3270_connect(hSession,wait);
752 745  
753 746 if(rc)
754 747 {
... ... @@ -758,6 +751,7 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *hSession,int wait)
758 751  
759 752 return 0;
760 753 }
  754 +*/
761 755  
762 756 LIB3270_EXPORT const char * lib3270_get_luname(H3270 *h)
763 757 {
... ...
macros.c
... ... @@ -254,15 +254,17 @@
254 254 switch(argc)
255 255 {
256 256 case 1:
257   - rc = lib3270_reconnect(hSession,0);
  257 + rc = lib3270_connect(hSession,0);
258 258 break;
259 259  
260 260 case 2:
261   - rc = lib3270_connect(hSession,argv[1],0);
  261 + lib3270_set_host(hSession,argv[1]);
  262 + rc = lib3270_connect(hSession,0);
262 263 break;
263 264  
264 265 case 3:
265   - rc = lib3270_connect(hSession,argv[1],atoi(argv[2]));
  266 + lib3270_set_host(hSession,argv[1]);
  267 + rc = lib3270_connect(hSession,atoi(argv[2]));
266 268 break;
267 269  
268 270 default:
... ...