/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <windows.h>
#include <winsock2.h>
#include "sysSocket.h"
#include "socketTransport.h"
/*
* Table of Windows Sockets errors, the specific exception we
* throw for the error, and the error text.
*
* Note that this table excludes OS dependent errors.
*/
static struct {
int errCode;
const char *errString;
} const winsock_errors[] = {
{ WSAEPROVIDERFAILEDINIT, "Provider initialization failed (check %SystemRoot%)" },
{ WSAEACCES, "Permission denied" },
{ WSAEADDRINUSE, "Address already in use" },
{ WSAEADDRNOTAVAIL, "Cannot assign requested address" },
{ WSAEAFNOSUPPORT, "Address family not supported by protocol family" },
{ WSAEALREADY, "Operation already in progress" },
{ WSAECONNABORTED, "Software caused connection abort" },
{ WSAECONNREFUSED, "Connection refused" },
{ WSAECONNRESET, "Connection reset by peer" },
{ WSAEDESTADDRREQ, "Destination address required" },
{ WSAEFAULT, "Bad address" },
{ WSAEHOSTDOWN, "Host is down" },
{ WSAEHOSTUNREACH, "No route to host" },
{ WSAEINPROGRESS, "Operation now in progress" },
{ WSAEINTR, "Interrupted function call" },
{ WSAEINVAL, "Invalid argument" },
{ WSAEISCONN, "Socket is already connected" },
{ WSAEMFILE, "Too many open files" },
{ WSAEMSGSIZE, "The message is larger than the maximum supported by the underlying transport" },
{ WSAENETDOWN, "Network is down" },
{ WSAENETRESET, "Network dropped connection on reset" },
{ WSAENETUNREACH, "Network is unreachable" },
{ WSAENOBUFS, "No buffer space available (maximum connections reached?)" },
{ WSAENOPROTOOPT, "Bad protocol option" },
{ WSAENOTCONN, "Socket is not connected" },
{ WSAENOTSOCK, "Socket operation on nonsocket" },
{ WSAEOPNOTSUPP, "Operation not supported" },
{ WSAEPFNOSUPPORT, "Protocol family not supported" },
{ WSAEPROCLIM, "Too many processes" },
{ WSAEPROTONOSUPPORT, "Protocol not supported" },
{ WSAEPROTOTYPE, "Protocol wrong type for socket" },
{ WSAESHUTDOWN, "Cannot send after socket shutdown" },
{ WSAESOCKTNOSUPPORT, "Socket type not supported" },
{ WSAETIMEDOUT, "Connection timed out" },
{ WSATYPE_NOT_FOUND, "Class type not found" },
{ WSAEWOULDBLOCK, "Resource temporarily unavailable" },
{ WSAHOST_NOT_FOUND, "Host not found" },
{ WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available" },
{ WSANOTINITIALISED, "Successful WSAStartup not yet performed" },
{ WSANO_DATA, "Valid name, no data record of requested type" },
{ WSANO_RECOVERY, "This is a nonrecoverable error" },
{ WSASYSNOTREADY, "Network subsystem is unavailable" },
{ WSATRY_AGAIN, "Nonauthoritative host not found" },
{ WSAVERNOTSUPPORTED, "Winsock.dll version out of range" },
{ WSAEDISCON, "Graceful shutdown in progress" },
{ WSA_OPERATION_ABORTED, "Overlapped operation aborted" },
};
/*
* Initialize Windows Sockets API support
*/
{
switch (reason) {
case DLL_PROCESS_ATTACH:
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
WSACleanup();
break;
default:
break;
}
return TRUE;
}
/*
* If we get a nonnull function pointer it might still be the case
* that some other thread is in the process of initializing the socket
* function pointer table, but our pointer should still be good.
*/
int
}
int
if (rv == SOCKET_ERROR) {
return DBG_EINPROGRESS;
}
}
return rv;
}
int rv;
struct timeval t;
if (rv == 0) {
return SYS_ERR; /* timeout */
}
/*
* Check if there was an error - this is preferable to check if
* the socket is writable because some versions of Windows don't
* report a connected socket as being writable.
*/
return SYS_OK;
}
/*
* Unable to establish connection - to get the reason we must
* call getsockopt.
*/
return SYS_ERR;
}
int
}
int
}
int
}
int
}
int
}
struct hostent *
return gethostbyname(hostname);
}
unsigned short
}
int
if (fd != SOCKET_ERROR) {
}
return fd;
}
int
struct linger l;
int len = sizeof(l);
if (l.l_onoff == 0) {
}
}
return closesocket(fd);
}
/* Additions to original follow */
int
}
}
}
unsigned short
}
int
}
}
/*
* Below Adapted from PlainSocketImpl.c, win32 version 1.18. Changed exception
* throws to returns of SYS_ERR; we should improve the error codes
* eventually. Changed java objects to values the debugger back end can
* more easily deal with.
*/
int
{
if (cmd == TCP_NODELAY) {
(char *)&onl, sizeof(long)) < 0) {
return SYS_ERR;
}
if(on) {
return SYS_ERR;
}
} else {
return SYS_ERR;
}
}
return SYS_ERR;
}
} else if (cmd == SO_REUSEADDR) {
/*
* On Windows the SO_REUSEADDR socket option doesn't implement
* BSD semantics. Specifically, the socket option allows multiple
* a process to bind with a previous connection in the TIME_WAIT
* state. Hence on Windows we never enable this option for TCP
* option.
*/
return SYS_ERR;
}
if (sotype != SOCK_STREAM) {
return SYS_ERR;
}
}
} else {
return SYS_ERR;
}
return SYS_OK;
}
int result = 0;
argp = 1;
} else {
argp = 0;
}
if (result == SOCKET_ERROR) {
return SYS_ERR;
} else {
return SYS_OK;
}
}
int
int rv;
struct timeval t;
if (rd) {
}
if (wr) {
}
if (rv >= 0) {
rv = 0;
rv |= DBG_POLLIN;
}
rv |= DBG_POLLOUT;
}
}
return rv;
}
int
sizeof(winsock_errors[0]);
int i;
/*
* Check table for known winsock errors
*/
i=0;
while (i < table_size) {
break;
}
i++;
}
if (i < table_size) {
} else {
}
return 0;
}
int
dbgsysTlsAlloc() {
return TlsAlloc();
}
void
}
void
}
void *
return TlsGetValue(index);
}
long
/* initialize on first usage */
if (fileTime_1_1_70 == 0) {
}
GetSystemTime(&st0);
}