@@ -0,0 +1,43 @@
+#include "input_win.h"
+
+ void init_wsa(void) {
+ WSADATA wsa;
+ WSAStartup(WINSOCK_VERSION, &wsa);
+ }
+ int windows_read(int fd, char *buffer, int len) {
+ struct timeval tv;
+ fd_set rfd;
+ retry:
+ FD_ZERO(&rfd);
+ FD_SET(fd, &rfd);
+ tv.tv_sec = 0;
+ tv.tv_usec = 200;
+ int rs;
+ int ret;
+ rs = select(fd+1, &rfd, NULL, NULL, &tv);
+ if (errno == EINTR) {
+ goto retry;
+ if (rs == -1) {
+ // error
+ return -1;
+ if (rs == 0 ) {
+ return 0;
+ if (FD_ISSET(fd, &rfd)) {
+ ret = recv(fd, buffer, len, 0);
+ if (ret == 0) {
+ // select, recv = 0: connection closed.
+ return ret;
@@ -0,0 +1,5 @@
+#include <winsock2.h>
+#include <string.h>
+void init_wsa(void);
+int windows_read(int fd, char *buffer, int len);
@@ -62,7 +62,7 @@ func Reader(d *Door) {
for {
read := C.windows_read(C.int(d.Config.Comm_handle), (*C.char)(readerbuffer), C.int(READ_SIZE))
r = int(read)
- log.Printf("windows_read: %d\n", r)
+ // log.Printf("windows_read: %d\n", r)
if r == -1 {
log.Println("window_read -1 (closed)")
@@ -71,6 +71,8 @@ func Writer(d *Door) {
err = syscall.WSASend(handle, &WSA_Buffer, 1, &DataWrite, UitnZero_1, nil, nil)
if err != nil {
fmt.Printf("write: %d bytes, error: %#v\n", DataWrite, err)
+ } else {
+ log.Printf("write %d bytes\n", DataWrite)
}
if (err != nil) || (l != DataWrite) {