7034299: Faulty winsock initialization code
Reviewed-by: dholmes, sla, ctornqvi
This commit is contained in:
parent
214b7d9dcf
commit
5b838d4ce1
@ -3768,6 +3768,8 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
static jint initSock();
|
||||
|
||||
// this is called _after_ the global arguments have been parsed
|
||||
jint os::init_2(void) {
|
||||
// Allocate a single page and mark it as readable for safepoint polling
|
||||
@ -3898,6 +3900,10 @@ jint os::init_2(void) {
|
||||
if (!success) UseNUMAInterleaving = false;
|
||||
}
|
||||
|
||||
if (initSock() != JNI_OK) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
@ -4894,42 +4900,24 @@ LONG WINAPI os::win32::serialize_fault_filter(struct _EXCEPTION_POINTERS* e) {
|
||||
// We don't build a headless jre for Windows
|
||||
bool os::is_headless_jre() { return false; }
|
||||
|
||||
|
||||
typedef CRITICAL_SECTION mutex_t;
|
||||
#define mutexInit(m) InitializeCriticalSection(m)
|
||||
#define mutexDestroy(m) DeleteCriticalSection(m)
|
||||
#define mutexLock(m) EnterCriticalSection(m)
|
||||
#define mutexUnlock(m) LeaveCriticalSection(m)
|
||||
|
||||
static bool sock_initialized = FALSE;
|
||||
static mutex_t sockFnTableMutex;
|
||||
|
||||
static void initSock() {
|
||||
static jint initSock() {
|
||||
WSADATA wsadata;
|
||||
|
||||
if (!os::WinSock2Dll::WinSock2Available()) {
|
||||
jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n",
|
||||
jio_fprintf(stderr, "Could not load Winsock (error: %d)\n",
|
||||
::GetLastError());
|
||||
return;
|
||||
return JNI_ERR;
|
||||
}
|
||||
if (sock_initialized == TRUE) return;
|
||||
|
||||
::mutexInit(&sockFnTableMutex);
|
||||
::mutexLock(&sockFnTableMutex);
|
||||
if (os::WinSock2Dll::WSAStartup(MAKEWORD(1,1), &wsadata) != 0) {
|
||||
jio_fprintf(stderr, "Could not initialize Winsock\n");
|
||||
if (os::WinSock2Dll::WSAStartup(MAKEWORD(2,2), &wsadata) != 0) {
|
||||
jio_fprintf(stderr, "Could not initialize Winsock (error: %d)\n",
|
||||
::GetLastError());
|
||||
return JNI_ERR;
|
||||
}
|
||||
sock_initialized = TRUE;
|
||||
::mutexUnlock(&sockFnTableMutex);
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
struct hostent* os::get_host_by_name(char* name) {
|
||||
if (!sock_initialized) {
|
||||
initSock();
|
||||
}
|
||||
if (!os::WinSock2Dll::WinSock2Available()) {
|
||||
return NULL;
|
||||
}
|
||||
return (struct hostent*)os::WinSock2Dll::gethostbyname(name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user