# HG changeset patch # User twisti # Date 1335294932 25200 # Node ID b0e4fdf19f29887bd2829cb1234ec01df793ef3b # Parent 6d69203a4cb0bae3f5762b5cd171ea54bb74b6a8 7157695: Add windows implementation of socket interface Reviewed-by: kvn, dholmes, twisti Contributed-by: Nils Eliasson diff -r 6d69203a4cb0 -r b0e4fdf19f29 hotspot/src/os/windows/vm/jvm_windows.h --- a/hotspot/src/os/windows/vm/jvm_windows.h Wed Apr 18 16:08:34 2012 -0700 +++ b/hotspot/src/os/windows/vm/jvm_windows.h Tue Apr 24 12:15:32 2012 -0700 @@ -59,7 +59,7 @@ #include -typedef unsigned int socklen_t; +typedef int socklen_t; // #include "jni.h" diff -r 6d69203a4cb0 -r b0e4fdf19f29 hotspot/src/os/windows/vm/os_windows.cpp --- a/hotspot/src/os/windows/vm/os_windows.cpp Wed Apr 18 16:08:34 2012 -0700 +++ b/hotspot/src/os/windows/vm/os_windows.cpp Tue Apr 24 12:15:32 2012 -0700 @@ -4820,99 +4820,92 @@ return (struct hostent*)os::WinSock2Dll::gethostbyname(name); } - int os::socket_close(int fd) { - ShouldNotReachHere(); - return 0; + return ::closesocket(fd); } int os::socket_available(int fd, jint *pbytes) { - ShouldNotReachHere(); - return 0; + int ret = ::ioctlsocket(fd, FIONREAD, (u_long*)pbytes); + return (ret < 0) ? 0 : 1; } int os::socket(int domain, int type, int protocol) { - ShouldNotReachHere(); - return 0; + return ::socket(domain, type, protocol); } int os::listen(int fd, int count) { - ShouldNotReachHere(); - return 0; + return ::listen(fd, count); } int os::connect(int fd, struct sockaddr* him, socklen_t len) { - ShouldNotReachHere(); - return 0; + return ::connect(fd, him, len); } int os::accept(int fd, struct sockaddr* him, socklen_t* len) { - ShouldNotReachHere(); - return 0; + return ::accept(fd, him, len); } int os::sendto(int fd, char* buf, size_t len, uint flags, struct sockaddr* to, socklen_t tolen) { - ShouldNotReachHere(); - return 0; + + return ::sendto(fd, buf, (int)len, flags, to, tolen); } int os::recvfrom(int fd, char *buf, size_t nBytes, uint flags, sockaddr* from, socklen_t* fromlen) { - ShouldNotReachHere(); - return 0; + + return ::recvfrom(fd, buf, (int)nBytes, flags, from, fromlen); } int os::recv(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::recv(fd, buf, (int)nBytes, flags); } int os::send(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::send(fd, buf, (int)nBytes, flags); } int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::send(fd, buf, (int)nBytes, flags); } int os::timeout(int fd, long timeout) { - ShouldNotReachHere(); - return 0; + fd_set tbl; + struct timeval t; + + t.tv_sec = timeout / 1000; + t.tv_usec = (timeout % 1000) * 1000; + + tbl.fd_count = 1; + tbl.fd_array[0] = fd; + + return ::select(1, &tbl, 0, 0, &t); } int os::get_host_name(char* name, int namelen) { - ShouldNotReachHere(); - return 0; + return ::gethostname(name, namelen); } int os::socket_shutdown(int fd, int howto) { - ShouldNotReachHere(); - return 0; + return ::shutdown(fd, howto); } int os::bind(int fd, struct sockaddr* him, socklen_t len) { - ShouldNotReachHere(); - return 0; + return ::bind(fd, him, len); } int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { - ShouldNotReachHere(); - return 0; + return ::getsockname(fd, him, len); } int os::get_sock_opt(int fd, int level, int optname, char* optval, socklen_t* optlen) { - ShouldNotReachHere(); - return 0; + return ::getsockopt(fd, level, optname, optval, optlen); } int os::set_sock_opt(int fd, int level, int optname, const char* optval, socklen_t optlen) { - ShouldNotReachHere(); - return 0; + return ::setsockopt(fd, level, optname, optval, optlen); }