This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
WIN-25.1: natPlainSocketImpl.cc [UPDATED]
- From: Adam Megacz <patches at lists dot megacz dot com>
- To: java-patches at gcc dot gnu dot org
- Date: 24 Feb 2002 18:15:50 -0800
- Subject: WIN-25.1: natPlainSocketImpl.cc [UPDATED]
- Organization: Myself
- References: <86lmdi1kx9.fsf@megacz.com>
Changed close from a #define to an actual function, added inline
keywords.
Ok to commit?
- a
2002-02-24 Adam Megacz <adam@xwt.org>
* java/net/natPlainSocketImpl.cc: Changed USE_WINSOCK to
WIN32, and added thunks for read(), write(), and close().
* java/net/natPlainSocketImpl.cc (accept, read, read):
Disabled timeouts on WIN32 pending discussion.
Index: natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.30
diff -u -r1.30 natPlainSocketImpl.cc
--- natPlainSocketImpl.cc 2002/02/07 03:24:01 1.30
+++ natPlainSocketImpl.cc 2002/02/25 02:21:07
@@ -10,22 +10,43 @@
#ifndef DISABLE_JAVA_NET
-#ifdef USE_WINSOCK
+#ifdef WIN32
#include <windows.h>
#include <winsock.h>
#include <errno.h>
#include <string.h>
+#undef STRICT
+#undef MAX_PRIORITY
+#undef MIN_PRIORITY
+#undef FIONREAD
+
+// stuff to make Win32 look POSIXy
+inline int close(int s) {
+ return closesocket(s);
+}
+inline int write(int s, void *buf, int len)
+{
+ return send(s, (char*)buf, len, 0);
+}
+inline int read(int s, void *buf, int len)
+{
+ return recv(s, (char*)buf, len, 0);
+}
+
+// these errors cannot occur on Win32
+#define ENOTCONN 0
+#define ECONNRESET 0
#ifndef ENOPROTOOPT
#define ENOPROTOOPT 109
#endif
-#else /* USE_WINSOCK */
+#else /* WIN32 */
#include "posix.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <errno.h>
#include <string.h>
-#endif /* USE_WINSOCK */
+#endif /* WIN32 */
#endif /* DISABLE_JAVA_NET */
#if HAVE_BSTRING_H
@@ -334,6 +355,8 @@
socklen_t addrlen = sizeof(u);
int new_socket = 0;
+// FIXME: implement timeout support for Win32
+#ifndef WIN32
// Do timeouts via select since SO_RCVTIMEO is not always available.
if (timeout > 0)
{
@@ -350,6 +373,7 @@
throw new java::io::InterruptedIOException (
JvNewStringUTF("Accept timed out"));
}
+#endif /* WIN32 */
new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen);
if (new_socket < 0)
@@ -470,6 +494,8 @@
{
jbyte b;
+// FIXME: implement timeout support for Win32
+#ifndef WIN32
// Do timeouts via select.
if (timeout > 0)
{
@@ -491,6 +517,8 @@
// If select returns ok we know we either got signalled or read some data...
// either way we need to try to read.
}
+#endif /* WIN32 */
+
int r = ::read (fnum, &b, 1);
if (r == 0)
@@ -525,6 +553,8 @@
throw new java::lang::ArrayIndexOutOfBoundsException;
jbyte *bytes = elements (buffer) + offset;
+// FIXME: implement timeout support for Win32
+#ifndef WIN32
// Do timeouts via select.
if (timeout > 0)
{
@@ -550,8 +580,11 @@
throw iioe;
}
}
+#endif
+
// Read the socket.
- int r = _Jv_recv (::recv, fnum, (void *) bytes, count, 0);
+ int r = _Jv_recv ((int (*)(unsigned int, char*, int, int))(::recv),
+ fnum, (void *) bytes, count, 0);
if (r == 0)
return -1;
if (java::lang::Thread::interrupted())