This is an automated email from Gerrit.

Yun ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/6096

-- gerrit

commit 98eaab2db77818dbf2e7ed096e1fbb581cd06e36
Author: Yun Liu <[email protected]>
Date:   Fri Mar 12 15:07:13 2021 +0800

    remote_bitbang: Add Windows support
    
    Windows socket descriptor is not file descriptor, so when using 
remote_bitbang on Windows, it fails with "fdopen: failed to open write stream".
    
    This patch removes the file write stream, replaces it with socket write 
calls.
    
    Change-Id: Ifd7c8a4139a5ac51ecd2846835a7a947a90fe16c
    Signed-off-by: Yun Liu <[email protected]>

diff --git a/src/jtag/drivers/remote_bitbang.c 
b/src/jtag/drivers/remote_bitbang.c
index 6637952..3536913 100644
--- a/src/jtag/drivers/remote_bitbang.c
+++ b/src/jtag/drivers/remote_bitbang.c
@@ -33,7 +33,6 @@
 static char *remote_bitbang_host;
 static char *remote_bitbang_port;
 
-static FILE *remote_bitbang_file;
 static int remote_bitbang_fd;
 
 /* Circular buffer. When start == end, the buffer is empty. */
@@ -63,7 +62,7 @@ static int remote_bitbang_fill_buf(void)
                        contiguous_available_space = remote_bitbang_start -
                                remote_bitbang_end - 1;
                }
-               ssize_t count = read(remote_bitbang_fd,
+               ssize_t count = read_socket(remote_bitbang_fd,
                                remote_bitbang_buf + remote_bitbang_end,
                                contiguous_available_space);
                if (count > 0) {
@@ -73,7 +72,12 @@ static int remote_bitbang_fill_buf(void)
                } else if (count == 0) {
                        return ERROR_OK;
                } else if (count < 0) {
+#ifdef _WIN32
+                       errno = WSAGetLastError();
+                       if (errno == WSAEWOULDBLOCK) {
+#else
                        if (errno == EAGAIN) {
+#endif
                                return ERROR_OK;
                        } else {
                                LOG_ERROR("remote_bitbang_fill_buf: %s (%d)",
@@ -88,7 +92,9 @@ static int remote_bitbang_fill_buf(void)
 
 static int remote_bitbang_putc(int c)
 {
-       if (EOF == fputc(c, remote_bitbang_file)) {
+       char buf = c;
+       ssize_t count = write_socket(remote_bitbang_fd, &buf, sizeof(buf));
+       if (count < 0) {
                LOG_ERROR("remote_bitbang_putc: %s", strerror(errno));
                return ERROR_FAIL;
        }
@@ -97,20 +103,12 @@ static int remote_bitbang_putc(int c)
 
 static int remote_bitbang_quit(void)
 {
-       if (EOF == fputc('Q', remote_bitbang_file)) {
-               LOG_ERROR("fputs: %s", strerror(errno));
-               return ERROR_FAIL;
-       }
-
-       if (EOF == fflush(remote_bitbang_file)) {
-               LOG_ERROR("fflush: %s", strerror(errno));
+       if (remote_bitbang_putc('Q') == ERROR_FAIL) {
                return ERROR_FAIL;
        }
 
-       /* We only need to close one of the FILE*s, because they both use the 
same */
-       /* underlying file descriptor. */
-       if (EOF == fclose(remote_bitbang_file)) {
-               LOG_ERROR("fclose: %s", strerror(errno));
+       if (!close_socket(remote_bitbang_fd)) {
+               LOG_ERROR("close_socket: %s", strerror(errno));
                return ERROR_FAIL;
        }
 
@@ -138,16 +136,10 @@ static bb_value_t char_to_int(int c)
 /* Get the next read response. */
 static bb_value_t remote_bitbang_rread(void)
 {
-       if (EOF == fflush(remote_bitbang_file)) {
-               remote_bitbang_quit();
-               LOG_ERROR("fflush: %s", strerror(errno));
-               return BB_ERROR;
-       }
-
        /* Enable blocking access. */
        socket_block(remote_bitbang_fd);
        char c;
-       ssize_t count = read(remote_bitbang_fd, &c, 1);
+       ssize_t count = read_socket(remote_bitbang_fd, &c, 1);
        if (count == 1) {
                return char_to_int(c);
        } else {
@@ -288,13 +280,6 @@ static int remote_bitbang_init(void)
        if (remote_bitbang_fd < 0)
                return remote_bitbang_fd;
 
-       remote_bitbang_file = fdopen(remote_bitbang_fd, "w+");
-       if (remote_bitbang_file == NULL) {
-               LOG_ERROR("fdopen: failed to open write stream");
-               close(remote_bitbang_fd);
-               return ERROR_FAIL;
-       }
-
        LOG_INFO("remote_bitbang driver initialized");
        return ERROR_OK;
 }

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to