|
| 1 | +diff --git a/avrdude/ser_win32.c b/avrdude/ser_win32.c |
| 2 | +index fcaa55e..5fc17b1 100644 |
| 3 | +--- ser_win32.c |
| 4 | ++++ ser_win32.c |
| 5 | +@@ -628,9 +628,95 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen |
| 6 | + return 0; |
| 7 | + } |
| 8 | + |
| 9 | ++#ifdef HAVE_LIBWS2_32 |
| 10 | ++static int net_drain(union filedescriptor *fd, int display) |
| 11 | ++{ |
| 12 | ++ LPVOID lpMsgBuf; |
| 13 | ++ struct timeval timeout; |
| 14 | ++ fd_set rfds; |
| 15 | ++ int nfds; |
| 16 | ++ unsigned char buf; |
| 17 | ++ int rc; |
| 18 | ++ |
| 19 | ++ if (fd->ifd < 0) { |
| 20 | ++ avrdude_message(MSG_INFO, "%s: ser_drain(): connection not open\n", progname); |
| 21 | ++ exit(1); |
| 22 | ++ } |
| 23 | ++ |
| 24 | ++ if (display) { |
| 25 | ++ avrdude_message(MSG_INFO, "drain>"); |
| 26 | ++ } |
| 27 | ++ |
| 28 | ++ timeout.tv_sec = 0; |
| 29 | ++ timeout.tv_usec = 250000; |
| 30 | ++ |
| 31 | ++ while (1) { |
| 32 | ++ FD_ZERO(&rfds); |
| 33 | ++ FD_SET(fd->ifd, &rfds); |
| 34 | ++ |
| 35 | ++ reselect: |
| 36 | ++ nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &timeout); |
| 37 | ++ if (nfds == 0) { |
| 38 | ++ if (display) { |
| 39 | ++ avrdude_message(MSG_INFO, "<drain\n"); |
| 40 | ++ } |
| 41 | ++ break; |
| 42 | ++ } |
| 43 | ++ else if (nfds == -1) { |
| 44 | ++ if (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS) { |
| 45 | ++ avrdude_message(MSG_NOTICE, "%s: ser_drain(): programmer is not responding, reselecting\n", progname); |
| 46 | ++ goto reselect; |
| 47 | ++ } else { |
| 48 | ++ FormatMessage( |
| 49 | ++ FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 50 | ++ FORMAT_MESSAGE_FROM_SYSTEM | |
| 51 | ++ FORMAT_MESSAGE_IGNORE_INSERTS, |
| 52 | ++ NULL, |
| 53 | ++ WSAGetLastError(), |
| 54 | ++ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 55 | ++ (LPTSTR)&lpMsgBuf, |
| 56 | ++ 0, |
| 57 | ++ NULL); |
| 58 | ++ avrdude_message(MSG_INFO, "%s: ser_drain(): select(): %s\n", progname, (char *)lpMsgBuf); |
| 59 | ++ LocalFree(lpMsgBuf); |
| 60 | ++ exit(1); |
| 61 | ++ } |
| 62 | ++ } |
| 63 | ++ |
| 64 | ++ rc = recv(fd->ifd, &buf, 1, 0); |
| 65 | ++ if (rc < 0) { |
| 66 | ++ FormatMessage( |
| 67 | ++ FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 68 | ++ FORMAT_MESSAGE_FROM_SYSTEM | |
| 69 | ++ FORMAT_MESSAGE_IGNORE_INSERTS, |
| 70 | ++ NULL, |
| 71 | ++ WSAGetLastError(), |
| 72 | ++ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 73 | ++ (LPTSTR)&lpMsgBuf, |
| 74 | ++ 0, |
| 75 | ++ NULL); |
| 76 | ++ avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n", progname, (char *)lpMsgBuf); |
| 77 | ++ LocalFree(lpMsgBuf); |
| 78 | ++ exit(1); |
| 79 | ++ } |
| 80 | ++ |
| 81 | ++ if (display) { |
| 82 | ++ avrdude_message(MSG_INFO, "%02x ", buf); |
| 83 | ++ } |
| 84 | ++ } |
| 85 | ++ |
| 86 | ++ return 0; |
| 87 | ++} |
| 88 | ++#endif |
| 89 | + |
| 90 | + static int ser_drain(union filedescriptor *fd, int display) |
| 91 | + { |
| 92 | ++#ifdef HAVE_LIBWS2_32 |
| 93 | ++ if (serial_over_ethernet) { |
| 94 | ++ return net_drain(fd, display); |
| 95 | ++ } |
| 96 | ++#endif |
| 97 | ++ |
| 98 | + // int rc; |
| 99 | + unsigned char buf[10]; |
| 100 | + BOOL readres; |
| 101 | + |
0 commit comments