Introduce a sane interface function, from_backend(), for backends to
[u/mdw/putty] / raw.c
diff --git a/raw.c b/raw.c
index cf4eaee..3f82d7a 100644 (file)
--- a/raw.c
+++ b/raw.c
@@ -1,7 +1,13 @@
 #include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
+#ifndef AUTO_WINSOCK
+#ifdef WINSOCK_TWO
+#include <winsock2.h>
+#else
 #include <winsock.h>
+#endif
+#endif
 
 #include "putty.h"
 
@@ -48,8 +54,7 @@ static void s_write (void *buf, int len) {
 }
 
 static void c_write (char *buf, int len) {
-    while (len--) 
-        c_write1(*buf++);
+    from_backend(0, buf, len);
 }
 
 /*
@@ -131,6 +136,11 @@ static char *raw_init (HWND hwnd, char *host, int port, char **realhost) {
          default: return "WSAAsyncSelect(): unknown error";
        }
 
+    /*
+     * We have no pre-session phase.
+     */
+    begin_session();
+
     return NULL;
 }
 
@@ -149,8 +159,11 @@ static int raw_msg (WPARAM wParam, LPARAM lParam) {
      * the queue; so it's possible that we can get here even with s
      * invalid. If so, we return 1 and don't worry about it.
      */
-    if (s == INVALID_SOCKET)
+    if (s == INVALID_SOCKET) {
+        closesocket(s);
+        s = INVALID_SOCKET;
        return 1;
+    }
 
     if (WSAGETSELECTERROR(lParam) != 0)
        return -WSAGETSELECTERROR(lParam);
@@ -161,8 +174,11 @@ static int raw_msg (WPARAM wParam, LPARAM lParam) {
        ret = recv(s, buf, sizeof(buf), 0);
        if (ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK)
            return 1;
-       if (ret < 0)                   /* any _other_ error */
+       if (ret < 0) {                 /* any _other_ error */
+            closesocket(s);
+            s = INVALID_SOCKET;
            return -10000-WSAGetLastError();
+        }
        if (ret == 0) {
            s = INVALID_SOCKET;
            return 0;
@@ -226,5 +242,6 @@ Backend raw_backend = {
     raw_size,
     raw_special,
     raw_socket,
-    raw_sendok
+    raw_sendok,
+    1
 };