Created
October 11, 2012 08:37
-
-
Save shirok/3871019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ext/net/gauche-net.h b/ext/net/gauche-net.h | |
index 7377a36..07ee38a 100644 | |
--- a/ext/net/gauche-net.h | |
+++ b/ext/net/gauche-net.h | |
@@ -196,6 +196,10 @@ extern ScmObj Scm_InetAddressToString(ScmObj addr, int proto); | |
typedef struct ScmSocketRec { | |
SCM_HEADER; | |
Socket fd; /* INVALID_SOCKET if closed */ | |
+#ifdef GAUCHE_WINDOWS | |
+ int crt_fd; /* integer fd allocated by open_osfhandle. | |
+ -1 if CRT fd isn't allocated yet. */ | |
+#endif | |
int status; | |
int type; | |
ScmSockAddr *address; | |
diff --git a/ext/net/net.c b/ext/net/net.c | |
index 7b4ff02..e8b8b49 100644 | |
--- a/ext/net/net.c | |
+++ b/ext/net/net.c | |
@@ -92,6 +92,9 @@ ScmSocket *make_socket(Socket fd, int type) | |
ScmSocket *s = SCM_NEW(ScmSocket); | |
SCM_SET_CLASS(s, SCM_CLASS_SOCKET); | |
s->fd = fd; | |
+#ifdef GAUCHE_WINDOWS | |
+ s->crt_fd = -1; | |
+#endif | |
s->status = SCM_SOCKET_STATUS_NONE; | |
s->inPort = s->outPort = NULL; | |
s->address = NULL; | |
@@ -174,7 +177,10 @@ ScmObj Scm_SocketInputPort(ScmSocket *sock, int buffering) | |
#ifndef GAUCHE_WINDOWS | |
infd = sock->fd; | |
#else /*GAUCHE_WINDOWS*/ | |
- infd = _open_osfhandle(sock->fd, O_RDONLY); | |
+ if (sock->crt_fd < 0) { | |
+ sock->crt_fd = _open_osfhandle(sock->fd, 0); | |
+ } | |
+ infd = sock->crt_fd; | |
#endif /*GAUCHE_WINDOWS*/ | |
if (infd == INVALID_SOCKET) sockport_err(sock, "input"); | |
@@ -201,7 +207,10 @@ ScmObj Scm_SocketOutputPort(ScmSocket *sock, int buffering) | |
#ifndef GAUCHE_WINDOWS | |
outfd = sock->fd; | |
#else /*GAUCHE_WINDOWS*/ | |
- outfd = _open_osfhandle(sock->fd, 0); | |
+ if (sock->crt_fd < 0) { | |
+ sock->crt_fd = _open_osfhandle(sock->fd, 0); | |
+ } | |
+ outfd = sock->crt_fd; | |
#endif /*GAUCHE_WINDOWS*/ | |
if (outfd == INVALID_SOCKET) sockport_err(sock, "output"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment