Created
January 18, 2011 22:42
-
-
Save ghazel/785315 to your computer and use it in GitHub Desktop.
windows io junk to get io.cpp to compile. might be wrong, certainly not entirely right.
This file contains 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/vm/builtin/io.cpp b/vm/builtin/io.cpp | |
index 64989ce..a5e7321 100644 | |
--- a/vm/builtin/io.cpp | |
+++ b/vm/builtin/io.cpp | |
@@ -5,6 +5,7 @@ | |
#include <fcntl.h> | |
#ifdef RBX_WINDOWS | |
#include <winsock2.h> | |
+#include <ws2tcpip.h> | |
#else | |
#include <sys/ioctl.h> | |
#include <sys/socket.h> | |
@@ -34,6 +35,30 @@ | |
#include "capi/handle.hpp" | |
+#include "vm/windows_compat.h" | |
+ | |
+ | |
+// XXX: where should this go? | |
+#ifdef RBX_WINDOWS | |
+int fcntl(int fd, int cmd, int arg) | |
+{ | |
+ u_long ioctlArg; | |
+ | |
+ if (cmd != F_SETFL) { | |
+ errno = EINVAL; | |
+ return -1; | |
+ } | |
+ | |
+ if (arg & O_NONBLOCK) { | |
+ ioctlArg = 1; | |
+ } else { | |
+ ioctlArg = 0; | |
+ } | |
+ return ioctlsocket(fd, FIONBIO, &ioctlArg); | |
+} | |
+#endif | |
+ | |
+ | |
namespace rubinius { | |
void IO::init(STATE) { | |
GO(io).set(state->new_class("IO", G(object))); | |
@@ -436,10 +461,14 @@ namespace rubinius { | |
} | |
void IO::set_mode(STATE) { | |
- int acc_mode = fcntl(to_fd(), F_GETFL); | |
+ // XXX: is this the right default? | |
+ int acc_mode = 0; | |
+#ifdef F_GETFL | |
+ acc_mode = fcntl(to_fd(), F_GETFL); | |
if(acc_mode < 0) { | |
Exception::errno_error(state); | |
} | |
+#endif | |
mode(state, Fixnum::from(acc_mode)); | |
} | |
@@ -695,6 +724,7 @@ namespace rubinius { | |
return ary; | |
} | |
+#ifndef RBX_WINDOWS | |
static const char* unixpath(struct sockaddr_un *sockaddr, socklen_t len) { | |
if (sockaddr->sun_path < (char*)sockaddr + len) { | |
return sockaddr->sun_path; | |
@@ -708,6 +738,7 @@ namespace rubinius { | |
ary->set(state, 1, String::create(state, unixpath(addr, len))); | |
return ary; | |
} | |
+#endif | |
Object* IO::socket_read(STATE, Fixnum* bytes, Fixnum* flags, Fixnum* type, | |
CallFrame* calling_environment) { | |
@@ -729,7 +760,7 @@ namespace rubinius { | |
{ | |
GCIndependent guard(state, calling_environment); | |
bytes_read = recvfrom(descriptor()->to_native(), | |
- buffer->byte_address(), size, | |
+ (char*)buffer->byte_address(), size, | |
flags->to_native(), | |
(struct sockaddr*)buf, &alen); | |
} | |
@@ -766,9 +797,12 @@ namespace rubinius { | |
ary->set(state, 1, Qnil); | |
} | |
break; | |
+// XXX: return an error instead? | |
+#ifndef RBX_WINDOWS | |
case 2: // unix | |
ary->set(state, 1, unixaddr(state, (struct sockaddr_un*)buf, alen)); | |
break; | |
+#endif | |
default: | |
ary->set(state, 1, String::create(state, buf, alen)); | |
} | |
@@ -783,8 +817,11 @@ namespace rubinius { | |
if(op == state->symbol("tty?")) { | |
return isatty(fd) ? Qtrue : Qfalse; | |
+// XXX: return a placeholder instead? | |
+#ifndef RBX_WINDOWS | |
} else if(op == state->symbol("ttyname")) { | |
return String::create(state, ttyname(fd)); | |
+#endif | |
} else { | |
return Qnil; | |
} | |
@@ -1137,8 +1174,11 @@ failed: /* try next '*' position */ | |
} | |
void IO::set_nonblock(STATE) { | |
+ int flags = 0; | |
+#ifdef F_GETFL | |
int flags = fcntl(descriptor_->to_native(), F_GETFL); | |
if(flags == -1) return; | |
+#endif | |
if((flags & O_NONBLOCK) == 0) { | |
flags |= O_NONBLOCK; | |
diff --git a/vm/windows_compat.h b/vm/windows_compat.h | |
index 5b92464..444a6b1 100644 | |
--- a/vm/windows_compat.h | |
+++ b/vm/windows_compat.h | |
@@ -26,12 +26,78 @@ int uname(struct utsname *name); | |
int socketpair(int domain, int type, int protocol, int socket_vector[2]); | |
int pipe(int fildes[2]); | |
+#define SHUT_RD SD_RECEIVE | |
+#define SHUT_WR SD_SEND | |
+#define SHUT_RDWR SD_BOTH | |
+#define F_SETFL 1 | |
+#define O_NONBLOCK 1 | |
+ | |
+// XXX: re-defined in pthread | |
+//#define EWOULDBLOCK WSAEWOULDBLOCK | |
+#define EINPROGRESS WSAEINPROGRESS | |
+#define EALREADY WSAEALREADY | |
+#define ENOTSOCK WSAENOTSOCK | |
+#define EDESTADDRREQ WSAEDESTADDRREQ | |
+#define EMSGSIZE WSAEMSGSIZE | |
+#define EPROTOTYPE WSAEPROTOTYPE | |
+#define ENOPROTOOPT WSAENOPROTOOPT | |
+#define EPROTONOSUPPORT WSAEPROTONOSUPPORT | |
+#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT | |
+#define EOPNOTSUPP WSAEOPNOTSUPP | |
+#define EPFNOSUPPORT WSAEPFNOSUPPORT | |
+#define EAFNOSUPPORT WSAEAFNOSUPPORT | |
+#define EADDRINUSE WSAEADDRINUSE | |
+#define EADDRNOTAVAIL WSAEADDRNOTAVAIL | |
+#define ENETDOWN WSAENETDOWN | |
+#define ENETUNREACH WSAENETUNREACH | |
+#define ENETRESET WSAENETRESET | |
+#define ECONNABORTED WSAECONNABORTED | |
+#define ECONNRESET WSAECONNRESET | |
+#define ENOBUFS WSAENOBUFS | |
+#define EISCONN WSAEISCONN | |
+#define ENOTCONN WSAENOTCONN | |
+#define ESHUTDOWN WSAESHUTDOWN | |
+#define ETOOMANYREFS WSAETOOMANYREFS | |
+// XXX: re-defined in pthread | |
+//#define ETIMEDOUT WSAETIMEDOUT | |
+#define ECONNREFUSED WSAECONNREFUSED | |
+#define ELOOP WSAELOOP | |
+//#define ENAMETOOLONG WSAENAMETOOLONG | |
+#define EHOSTDOWN WSAEHOSTDOWN | |
+#define EHOSTUNREACH WSAEHOSTUNREACH | |
+//#define ENOTEMPTY WSAENOTEMPTY | |
+#define EPROCLIM WSAEPROCLIM | |
+#define EUSERS WSAEUSERS | |
+#define EDQUOT WSAEDQUOT | |
+#define ESTALE WSAESTALE | |
+#define EREMOTE WSAEREMOTE | |
+ | |
// file system | |
char* realpath(const char* file_name, char* resolved_name); | |
// time | |
#define timezone _timezone | |
+#define timeradd(tvp, uvp, vvp) \ | |
+ do { \ | |
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ | |
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ | |
+ if ((vvp)->tv_usec >= 1000000) { \ | |
+ (vvp)->tv_sec++; \ | |
+ (vvp)->tv_usec -= 1000000; \ | |
+ } \ | |
+ } while (0) | |
+#define timersub(tvp, uvp, vvp) \ | |
+ do { \ | |
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ | |
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ | |
+ if ((vvp)->tv_usec < 0) { \ | |
+ (vvp)->tv_sec--; \ | |
+ (vvp)->tv_usec += 1000000; \ | |
+ } \ | |
+ } while (0) | |
+ | |
+ | |
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); | |
#endif // RBX_WINDOWS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment