aboutsummaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-06 11:19:27 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-06 11:19:27 +0000
commit1acf7e6b018031df7d1413ae4d67e230034d0e20 (patch)
tree69c8086b74fd7ea683469ed0da69e365a02763db /win32
parent3bd61a71a07d5ca96aaf3c34860a61e5527a6e78 (diff)
downloadruby-1acf7e6b018031df7d1413ae4d67e230034d0e20.tar.gz
* io.c (is_socket): new function.
* io.c (rb_io_close_read, rb_io_close_write): use is_socket(). * io.c (rb_io_fptr_finalize): need to check fptr->f before calling rb_io_fptr_cleanup(). * io.c (pipe_open): win32 pipe support (experimental). * win32/win32.[ch] (rb_w32_pipe_exec): return file descripters instead of FILE structure. * win32/win32.[ch] (rb_w32_is_socket): new function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c42
-rw-r--r--win32/win32.h3
2 files changed, 19 insertions, 26 deletions
diff --git a/win32/win32.c b/win32/win32.c
index ed6402cc62..6dc8fffe4e 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -675,7 +675,7 @@ rb_w32_join_argv(char *cmd, char *const *argv)
pid_t
rb_w32_pipe_exec(const char *cmd, const char *prog, int mode,
- FILE **fpr, FILE **fpw)
+ int *pr, int *pw)
{
struct ChildRecord* child;
HANDLE hReadIn, hReadOut;
@@ -687,7 +687,6 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode,
BOOL reading, writing;
int fd;
int pipemode;
- char modes[3];
int ret;
/* Figure out what we're doing... */
@@ -695,12 +694,9 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode,
reading = ((mode & O_RDWR) || !writing) ? TRUE : FALSE;
if (mode & O_BINARY) {
pipemode = O_BINARY;
- modes[1] = 'b';
- modes[2] = '\0';
}
else {
pipemode = O_TEXT;
- modes[1] = '\0';
}
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
@@ -767,10 +763,10 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode,
/* associate handle to fp */
if (reading) {
- fd = rb_w32_open_osfhandle((long)hDupInFile,
- (_O_RDONLY | pipemode));
+ *pr = rb_w32_open_osfhandle((long)hDupInFile,
+ (_O_RDONLY | pipemode));
CloseHandle(hReadOut);
- if (fd == -1) {
+ if (*pr == -1) {
CloseHandle(hDupInFile);
read_open_failed:
if (writing) {
@@ -780,30 +776,20 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode,
CloseChildHandle(child);
break;
}
- modes[0] = 'r';
- if ((*fpr = (FILE *)fdopen(fd, modes)) == NULL) {
- _close(fd);
- goto read_open_failed;
- }
}
if (writing) {
- fd = rb_w32_open_osfhandle((long)hDupOutFile,
- (_O_WRONLY | pipemode));
+ *pw = rb_w32_open_osfhandle((long)hDupOutFile,
+ (_O_WRONLY | pipemode));
CloseHandle(hWriteIn);
- if (fd == -1) {
+ if (*pw == -1) {
CloseHandle(hDupOutFile);
write_open_failed:
if (reading) {
- fclose(*fpr);
+ close(*pr);
}
CloseChildHandle(child);
break;
}
- modes[0] = 'w';
- if ((*fpw = (FILE *)fdopen(fd, modes)) == NULL) {
- _close(fd);
- goto write_open_failed;
- }
}
ret = child->pid;
} while (0));
@@ -1672,8 +1658,14 @@ rb_w32_open_osfhandle(long osfhandle, int flags)
#undef getsockopt
+int
+rb_w32_is_socket(int fd)
+{
+ return is_socket(TO_SOCKET(fd));
+}
+
static int
-is_socket(SOCKET fd)
+is_socket(SOCKET sock)
{
char sockbuf[80];
int optlen;
@@ -1682,7 +1674,7 @@ is_socket(SOCKET fd)
optlen = sizeof(sockbuf);
RUBY_CRITICAL({
- retval = getsockopt(fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
+ retval = getsockopt(sock, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
if (retval == SOCKET_ERROR) {
int iRet;
iRet = WSAGetLastError();
@@ -1692,7 +1684,7 @@ is_socket(SOCKET fd)
});
//
- // If we get here, then fd is actually a socket.
+ // If we get here, then sock is actually a socket.
//
return result;
diff --git a/win32/win32.h b/win32/win32.h
index 16acd1c955..4ca3b299bc 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -138,8 +138,9 @@ struct timezone {
#endif
extern void NtInitialize(int *, char ***);
extern int rb_w32_cmdvector(const char *, char ***);
-extern pid_t rb_w32_pipe_exec(const char *, const char *, int, FILE **, FILE **);
+extern pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
extern int flock(int fd, int oper);
+extern int rb_w32_is_socket(int);
extern int rb_w32_accept(int, struct sockaddr *, int *);
extern int rb_w32_bind(int, struct sockaddr *, int);
extern int rb_w32_connect(int, struct sockaddr *, int);