]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Better tls_read function
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 10 Aug 2024 00:21:02 +0000 (20:21 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 10 Aug 2024 00:21:02 +0000 (20:21 -0400)
lib/subrou.c
lib/unitls.c

index ee8cbf8f2a775b07888fe2f6537206a758a9a564..0ff04c6b70ac30c7bdda6f70a73c967c7bb69be4 100644 (file)
@@ -20,7 +20,7 @@
 
 //version definition 
 #define VERSION "0.3"
-#define RELEASE "39"
+#define RELEASE "40"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index 6dc0e6fdce92146529b03c8de82c2e64e68cb46c..18415d9783311efda1f9f4ec718ff93053fff546 100644 (file)
@@ -501,8 +501,8 @@ if (tls!=(TLSTYP *)0) {
     switch (sofar) {
       case -1     :       //trouble to write
         switch (status=SSL_get_error(tls->ssl,-1)) {
-          case SSL_ERROR_WANT_READ        :     //"wanted" error
-          case SSL_ERROR_WANT_WRITE       :
+          case SSL_ERROR_WANT_READ        :     //
+          case SSL_ERROR_WANT_WRITE       :     //"Wanted" error
             (void) printf("JMPDBG SSL_get_error='%d'\n",status);
             (void) usleep(1000);
             count++;
@@ -555,16 +555,59 @@ return sent;
 PUBLIC int tls_read(TLSTYP *tls,char *buffer,int maxread)
 
 {
+#define OPEP    "unitls.c:tls_read"
+
 int got;
 
 got=-1;
 if (tls!=(TLSTYP *)0) {
-  if ((got=SSL_read(tls->ssl,buffer,maxread))<0) {
-    (void) showtlserror(tls,got,"Trouble to read data");
-    got=-1;
+  _Bool proceed;
+  int count;
+
+  count=0;
+  proceed=true;
+
+  (void) printf("JMPDBG receiving\n");
+  while (proceed==true) {
+    int status;
+
+    proceed=false;
+    got=SSL_read(tls->ssl,buffer,maxread);
+    (void) printf("JMPDBG read got='%d' count='%d'\n",got,count);
+    switch (got) {
+      case -1     :       //trouble to write
+        switch (status=SSL_get_error(tls->ssl,-1)) {
+          case SSL_ERROR_WANT_READ        :     //"wanted" error
+          case SSL_ERROR_WANT_WRITE       :     //
+            (void) printf("JMPDBG SSL_get_error='%d'\n",status);
+            (void) usleep(1000);
+            break;
+          default                         :
+            (void) showtlserror(tls,-1,"%s Premature EOF with crypted link",OPEP);
+            break;
+          }
+        break;
+      case  0     :       //no char sent
+        switch (SSL_get_error(tls->ssl,0)) {
+          case SSL_ERROR_SYSCALL          :       //EOF received?
+            tls->goteof=true;
+            if (ERR_get_error()!=0)
+              (void) rou_alert(0,"%s wrong EOF",OPEP);
+            break;
+          default                         :
+            (void) rou_alert(0,"%s Unexpected SSL_read error='%d'",
+                                OPEP,SSL_get_error(tls->ssl,0));
+            (void) showtlserror(tls,0,"show SSL error",OPEP);
+            break;
+          }
+        break;
+      default     :       //some character received
+        break;
+      }
     }
   }
 return got;
+#undef  OPEP
 }
 /*
 ^L