提交 67e687a4 编写于 作者: N neliasso

7034299: Faulty winsock initialization code

Reviewed-by: dholmes, sla, ctornqvi
上级 b9b4fe51
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册