platform/shared/ruby/win32/win32.c in rhodes-1.2.2 vs platform/shared/ruby/win32/win32.c in rhodes-1.4.0
- old
+ new
@@ -433,17 +433,21 @@
}
typedef BOOL (WINAPI *cancel_io_t)(HANDLE);
static cancel_io_t cancel_io = NULL;
+static cancel_io_t cancel_socket_io = NULL;
static void
init_func(void)
{
if (!cancel_io)
cancel_io = (cancel_io_t)GetProcAddress(GetModuleHandle("kernel32"),
"CancelIo");
+
+ //if (!cancel_socket_io)
+ // cancel_socket_io = cancel_io ? cancel_io : NULL;
}
static void init_stdhandle(void);
#if _MSC_VER >= 1400
@@ -482,15 +486,15 @@
//
// initalize the winsock interface and insure that it's
// cleaned up at exit.
//
- version = MAKEWORD(2, 0);
+/* version = MAKEWORD(2, 0);
if (WSAStartup(version, &retdata))
rb_fatal ("Unable to locate winsock library!\n");
if (LOBYTE(retdata.wVersion) != 2)
- rb_fatal("could not find version 2 of winsock dll\n");
+ rb_fatal("could not find version 2 of winsock dll\n");*/
socklist = st_init_numtable();
NtSocketsInitialized = 1;
}
@@ -2430,10 +2434,11 @@
r = connect(TO_SOCKET(s), addr, addrlen);
if (r == SOCKET_ERROR) {
r = WSAGetLastError();
if (r != WSAEWOULDBLOCK) {
errno = map_errno(r);
+ r=-1;
}
else {
errno = EINPROGRESS;
r = -1;
}
@@ -2549,11 +2554,11 @@
StartSockets();
s = TO_SOCKET(fd);
st_lookup(socklist, (st_data_t)s, &data);
mode = (int)data;
- if (!cancel_io || (mode & O_NONBLOCK)) {
+ if (!cancel_socket_io || (mode & O_NONBLOCK)) {
RUBY_CRITICAL({
if (input) {
if (addr && addrlen)
r = recvfrom(s, buf, len, flags, addr, addrlen);
else
@@ -2611,19 +2616,21 @@
errno = map_errno(err);
/* thru */
case WAIT_OBJECT_0 + 1:
/* interrupted */
r = -1;
- cancel_io((HANDLE)s);
+ cancel_socket_io((HANDLE)s);
break;
}
}
else {
errno = map_errno(err);
r = -1;
}
- CloseHandle(&wol.hEvent);
+ //RHO
+ CloseHandle(wol.hEvent);
+ //
}
return r;
}
@@ -2686,59 +2693,59 @@
errno = map_errno(WSAGetLastError());
});
return r;
}
+#undef socket
static SOCKET
open_ifs_socket(int af, int type, int protocol)
{
unsigned long proto_buffers_len = 0;
int error_code;
SOCKET out = INVALID_SOCKET;
- if (WSAEnumProtocols(NULL, NULL, &proto_buffers_len) == SOCKET_ERROR) {
- error_code = WSAGetLastError();
- if (error_code == WSAENOBUFS) {
- WSAPROTOCOL_INFO *proto_buffers;
- int protocols_available = 0;
+ /*if (WSAEnumProtocols(NULL, NULL, &proto_buffers_len) == SOCKET_ERROR) {
+ error_code = WSAGetLastError();
+ if (error_code == WSAENOBUFS) {
+ WSAPROTOCOL_INFO *proto_buffers;
+ int protocols_available = 0;
- proto_buffers = (WSAPROTOCOL_INFO *)malloc(proto_buffers_len);
- if (!proto_buffers) {
- WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
- return INVALID_SOCKET;
- }
+ proto_buffers = (WSAPROTOCOL_INFO *)malloc(proto_buffers_len);
+ if (!proto_buffers) {
+ WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
+ return INVALID_SOCKET;
+ }
- protocols_available =
- WSAEnumProtocols(NULL, proto_buffers, &proto_buffers_len);
- if (protocols_available != SOCKET_ERROR) {
- int i;
- for (i = 0; i < protocols_available; i++) {
- if ((af != AF_UNSPEC && af != proto_buffers[i].iAddressFamily) ||
- (type != proto_buffers[i].iSocketType) ||
- (protocol != 0 && protocol != proto_buffers[i].iProtocol))
- continue;
+ protocols_available =
+ WSAEnumProtocols(NULL, proto_buffers, &proto_buffers_len);
+ if (protocols_available != SOCKET_ERROR) {
+ int i;
+ for (i = 0; i < protocols_available; i++) {
+ if ((af != AF_UNSPEC && af != proto_buffers[i].iAddressFamily) ||
+ (type != proto_buffers[i].iSocketType) ||
+ (protocol != 0 && protocol != proto_buffers[i].iProtocol))
+ continue;
- if ((proto_buffers[i].dwServiceFlags1 & XP1_IFS_HANDLES) == 0)
- continue;
+ if ((proto_buffers[i].dwServiceFlags1 & XP1_IFS_HANDLES) == 0)
+ continue;
- out = WSASocket(af, type, protocol, &(proto_buffers[i]), 0,
- WSA_FLAG_OVERLAPPED);
- break;
- }
- if (out == INVALID_SOCKET)
- out = WSASocket(af, type, protocol, NULL, 0, 0);
+ out = WSASocket(af, type, protocol, &(proto_buffers[i]), 0,
+ WSA_FLAG_OVERLAPPED);
+ break;
+ }
+ if (out == INVALID_SOCKET)
+ out = WSASocket(af, type, protocol, NULL, 0, 0);
+ }
+
+ free(proto_buffers);
}
+ }else */
+ out = socket(af, type, protocol);
- free(proto_buffers);
- }
- }
-
return out;
}
-#undef socket
-
int WSAAPI
rb_w32_socket(int af, int type, int protocol)
{
SOCKET s;
int fd;
@@ -3829,12 +3836,15 @@
qw |= ft->dwLowDateTime;
qw /= 10000; /* File time ticks at 0.1uS, clock at 1mS */
return (long) qw;
}
-int
-rb_w32_times(struct tms *tmbuf)
+#ifdef RUBY_EXPORT
+int rb_w32_times(struct tms *tmbuf)
+#else
+int times(struct tms *tmbuf)
+#endif
{
FILETIME create, exit, kernel, user;
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
tmbuf->tms_utime = filetime_to_clock(&user);
@@ -4057,13 +4067,16 @@
if (IsWin95()) pid = -pid;
return pid;
}
+#ifdef RUBY_EXPORT
+rb_pid_t rb_w32_getppid(void)
+#else
+rb_pid_t getppid(void)
+#endif
-rb_pid_t
-rb_w32_getppid(void)
{
static long (WINAPI *pNtQueryInformationProcess)(HANDLE, int, void *, ULONG, ULONG *) = NULL;
rb_pid_t ppid = 0;
if (!IsWin95() && rb_w32_osver() >= 5) {
@@ -4283,11 +4296,14 @@
return -1;
}
return 0;
}
-int
-rb_w32_pipe(int fds[2])
+#ifdef RUBY_EXPORT
+int rb_w32_pipe(int fds[2])
+#else
+int pipe(int fds[2])
+#endif
{
static DWORD serial = 0;
char name[] = "\\\\.\\pipe\\ruby0000000000000000-0000000000000000";
char *p;
SECURITY_ATTRIBUTES sec;