This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: use gnu.gcj.RawData as file handle


This patch fixes some portability problems in FileDescriptor.java. 
FileDescriptor had assumed file handles could be represented as a jint,
and that 0,1,2 represent stdin,stdout,stderr respectively.

Essentially I implemented Per Bothner's suggestions:

http://sourceware.cygnus.com/ml/java-discuss/2000-q1/msg00100.html

These changes build and run on Linux/x86 and Win32 without any apparent
problems.  I fixed some serious bugs in natFileDescriptorWin32.cc as
well.

Win32 still does not quite work, but it is getting closer.

However I have no way of knowing if anything in Ecos is broken with this
patch (is the Ecos port even useable?).


2000-04-14  Jeff Sturm  <jsturm@sigma6.com>

	* java/io/FileDescriptor.java (init): Add static initializer.
	(in,out,err): Do not initialize.
	(fd): Remove.
	(handle): Added new private member for native file handle.
	(open): Changed return type to gnu.gcj.RawData.
	(constructor): Initialize handle, not fd.

	* java/io/natFileDescriptorEcos.cc (open): Return handle, not fd.

	* java/io/natFileDescriptorPosix.cc (init): New function.
	(valid): Use handle, not fd.
	(open): Likewise.
	(write): Likewise.
	(close): Likewise.
	(seek): Likewise.
	(length): Likewise.
	(getFilePointer): Likewise.
	(read): Likewise.
	(available): Likewise.

	* java/io/natFileDescriptorWin32.cc (winerr): Change return
	type to jstring.  Add `errnum' argument.  Allocate message buffer
	on stack.
	(init): New method.
	(valid): Use handle, not fd.  Get error code for winerr.
	(sync): Likewise.
	(open): Change file create mode to OPEN_ALWAYS.  Seek to end of
	file if APPEND is set.  Do not overwrite file if EXCL is set.
	Build error message in a StringBuffer.  Use handle, not fd.
	(write): Use handle, not fd.  Get error code for winerr.
	(close): Likewise.
	(seek): Likewise.
	(length): Likewise.
	(read): Likewise.

	* java/lang/natPosixProcess.cc: Cast file descriptors to
	<gnu::gcj::RawData *> handles.

	* java/net/natPlainDatagramSocketImpl.cc (create): Cast socket
	descriptor to <gnu::gcj::RawData *> handle.
	(receive): Don't use select() if not available.

	* java/net/natPlainSocketImpl.cc (create): Cast socket
	descriptor to <gnu::gcj::RawData *> handle.
	(accept): Don't use select() if not available.

-- 
Jeff Sturm
jsturm@sigma6.com
Index: java/io/FileDescriptor.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/FileDescriptor.java,v
retrieving revision 1.5
diff -u -r1.5 FileDescriptor.java
--- FileDescriptor.java	2000/03/07 19:55:26	1.5
+++ FileDescriptor.java	2000/04/14 18:34:03
@@ -24,10 +24,17 @@
 // if need be.
 public final class FileDescriptor
 {
-  public static final FileDescriptor in = new FileDescriptor (0);
-  public static final FileDescriptor out = new FileDescriptor (1);
-  public static final FileDescriptor err = new FileDescriptor (2);
+  public static final FileDescriptor in;
+  public static final FileDescriptor out;
+  public static final FileDescriptor err;
 
+  private static native void init();
+
+  static
+  {
+    init();
+  }
+
   public native void sync () throws SyncFailedException;
   public native boolean valid ();
 
@@ -46,15 +53,16 @@
   // Open a file.  MODE is a combination of the above mode flags.
   FileDescriptor (String path, int mode) throws FileNotFoundException
   {
-    fd = open (path, mode);
+    handle = open (path, mode);
   }
 
   public FileDescriptor ()
   {
-    fd = -1;
+    handle = null;
   }
 
-  native int open (String path, int mode) throws FileNotFoundException;
+  native gnu.gcj.RawData open (String path, int mode)
+    throws FileNotFoundException;
   native void write (int b) throws IOException;
   native void write (byte[] b, int offset, int len)
     throws IOException, NullPointerException, IndexOutOfBoundsException;
@@ -79,11 +87,11 @@
   // Ordinarily that wouldn't work, either, but in our case we know
   // the access comes from C++, where "package private" is translated
   // into "public".  Eww.
-  FileDescriptor (int desc)
+  FileDescriptor (gnu.gcj.RawData desc)
   {
-    fd = desc;
+    handle = desc;
   }
 
   // System's notion of file descriptor.
-  private int fd;
+  private gnu.gcj.RawData handle;
 }
Index: java/io/natFileDescriptorEcos.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/natFileDescriptorEcos.cc,v
retrieving revision 1.4
diff -u -r1.4 natFileDescriptorEcos.cc
--- natFileDescriptorEcos.cc	2000/03/07 19:55:26	1.4
+++ natFileDescriptorEcos.cc	2000/04/14 18:34:04
@@ -61,7 +61,7 @@
 jint
 java::io::FileDescriptor::open (jstring path, jint jflags)
 {
-  return fd;
+  return handle;
 }
 
 void
Index: java/io/natFileDescriptorPosix.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.7
diff -u -r1.7 natFileDescriptorPosix.cc
--- natFileDescriptorPosix.cc	2000/03/07 19:55:26	1.7
+++ natFileDescriptorPosix.cc	2000/04/14 18:34:04
@@ -49,11 +49,22 @@
 
 #define NO_FSYNC_MESSAGE "sync unsupported"
 
+void
+java::io::FileDescriptor::init (void)
+{
+  in = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (0));
+  out = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (1));
+  err = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (2));
+}
+
 jboolean
 java::io::FileDescriptor::valid (void)
 {
   struct stat sb;
-  return ::fstat (fd, &sb) == 0;
+  return ::fstat (reinterpret_cast<int> (handle), &sb) == 0;
 }
 
 void
@@ -62,14 +73,15 @@
   // Some files don't support fsync.  We don't bother reporting these
   // as errors.
 #ifdef HAVE_FSYNC
-  if (::fsync (fd) && errno != EROFS && errno != EINVAL)
+  if (::fsync (reinterpret_cast<int> (handle))
+      && errno != EROFS && errno != EINVAL)
     JvThrow (new SyncFailedException (JvNewStringLatin1 (strerror (errno))));
 #else
   JvThrow (new SyncFailedException (JvNewStringLatin1 (NO_FSYNC_MESSAGE)));
 #endif
 }
 
-jint
+gnu::gcj::RawData *
 java::io::FileDescriptor::open (jstring path, jint jflags)
 {
   // FIXME: eww.
@@ -111,14 +123,14 @@
       sprintf (msg, "%s: %s", buf, strerror (errno));
       JvThrow (new FileNotFoundException (JvNewStringLatin1 (msg)));
     }
-  return fd;
+  return reinterpret_cast<gnu::gcj::RawData *> (fd);
 }
 
 void
 java::io::FileDescriptor::write (jint b)
 {
   jbyte d = (jbyte) b;
-  int r = ::write (fd, &d, 1);
+  int r = ::write (reinterpret_cast<int> (handle), &d, 1);
   if (java::lang::Thread::interrupted())
     {
       InterruptedIOException *iioe
@@ -139,7 +151,7 @@
   if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
     JvThrow (new java::lang::ArrayIndexOutOfBoundsException);
   jbyte *bytes = elements (b) + offset;
-  int r = ::write (fd, bytes, len);
+  int r = ::write (reinterpret_cast<int> (handle), bytes, len);
   if (java::lang::Thread::interrupted())
     {
       InterruptedIOException *iioe
@@ -155,8 +167,8 @@
 void
 java::io::FileDescriptor::close (void)
 {
-  jint save = fd;
-  fd = -1;
+  int save = reinterpret_cast<int> (handle);
+  handle = reinterpret_cast<gnu::gcj::RawData *> (-1);
   if (::close (save))
     JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
 }
@@ -172,7 +184,8 @@
   if ((whence == SET && pos > len) || (whence == CUR && here + pos > len))
     JvThrow (new EOFException);
 
-  off_t r = ::lseek (fd, (off_t) pos, whence == SET ? SEEK_SET : SEEK_CUR);
+  off_t r = ::lseek (reinterpret_cast<int> (handle), (off_t) pos,
+    whence == SET ? SEEK_SET : SEEK_CUR);
   if (r == -1)
     JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
   return r;
@@ -182,7 +195,7 @@
 java::io::FileDescriptor::length (void)
 {
   struct stat sb;
-  if (::fstat (fd, &sb))
+  if (::fstat (reinterpret_cast<int> (handle), &sb))
     JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
   return sb.st_size;
 }
@@ -190,7 +203,7 @@
 jlong
 java::io::FileDescriptor::getFilePointer (void)
 {
-  off_t r = ::lseek (fd, 0, SEEK_CUR);
+  off_t r = ::lseek (reinterpret_cast<int> (handle), 0, SEEK_CUR);
   if (r == -1)
     JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
   return r;
@@ -200,7 +213,7 @@
 java::io::FileDescriptor::read (void)
 {
   jbyte b;
-  int r = ::read (fd, &b, 1);
+  int r = ::read (reinterpret_cast<int> (handle), &b, 1);
   if (r == 0)
     return -1;
   if (java::lang::Thread::interrupted())
@@ -224,7 +237,7 @@
   if (offset < 0 || count < 0 || offset + count > bsize)
     JvThrow (new java::lang::ArrayIndexOutOfBoundsException);
   jbyte *bytes = elements (buffer) + offset;
-  int r = ::read (fd, bytes, count);
+  int r = ::read (reinterpret_cast<int> (handle), bytes, count);
   if (r == 0)
     return -1;
   if (java::lang::Thread::interrupted())
@@ -243,6 +256,7 @@
 java::io::FileDescriptor::available (void)
 {
 #if defined (FIONREAD) || defined (HAVE_SELECT) || defined (HAVE_FSTAT)
+  int fd = reinterpret_cast<int> (handle);
   long num = 0;
   int r = 0;
   bool num_set = false;
Index: java/io/natFileDescriptorWin32.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/natFileDescriptorWin32.cc,v
retrieving revision 1.1
diff -u -r1.1 natFileDescriptorWin32.cc
--- natFileDescriptorWin32.cc	2000/03/15 22:03:19	1.1
+++ natFileDescriptorWin32.cc	2000/04/14 18:34:04
@@ -28,53 +28,62 @@
 #include <java/lang/ArrayIndexOutOfBoundsException.h>
 #include <java/lang/NullPointerException.h>
 #include <java/lang/String.h>
+#include <java/lang/StringBuffer.h>
 #include <java/lang/Thread.h>
 #include <java/io/FileNotFoundException.h>
 
-static char *
-winerr (void)
+static jstring
+winerr (DWORD errnum)
 {
-  static LPVOID last = NULL;
-  LPVOID old = NULL;
+  char buf[1000];
+  jstring str;
+  int n;
 
-  if (last)
-    old = last;
-
-  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
-    FORMAT_MESSAGE_FROM_SYSTEM |
+  n = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
     FORMAT_MESSAGE_IGNORE_INSERTS,
     NULL,
-    GetLastError(),
-    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-    (LPTSTR) &last,
+    errnum,
     0,
+    buf,
+    sizeof buf,
     NULL);
+
+  str = JvNewStringLatin1 (n > 0 ? buf : "unknown error");
 
-  if (old)
-    LocalFree (old);
+  return str;
+}
 
-  return (char *)last;
+void
+java::io::FileDescriptor::init (void)
+{
+  in = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (GetStdHandle (STD_INPUT_HANDLE)));
+  out = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (GetStdHandle (STD_OUTPUT_HANDLE)));
+  err = new java::io::FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (GetStdHandle (STD_ERROR_HANDLE)));
 }
 
 jboolean
 java::io::FileDescriptor::valid (void) {
   BY_HANDLE_FILE_INFORMATION info;
-  return GetFileInformationByHandle ((HANDLE)fd, &info) != 0;
+  return GetFileInformationByHandle (
+    reinterpret_cast<HANDLE> (handle), &info) != 0;
 }
 
 void
 java::io::FileDescriptor::sync (void) {
-  if (! FlushFileBuffers ((HANDLE)fd))
-    JvThrow (new SyncFailedException (JvNewStringLatin1 (winerr ())));
+  if (! FlushFileBuffers (reinterpret_cast<HANDLE> (handle)))
+    JvThrow (new SyncFailedException (winerr (GetLastError ())));
 }
 
-jint
+gnu::gcj::RawData *
 java::io::FileDescriptor::open (jstring path, jint jflags) {
 
-  HANDLE handle = NULL;
+  HANDLE h = NULL;
   DWORD access = 0;
-  DWORD share = FILE_SHARE_READ;
-  DWORD create = OPEN_EXISTING;
+  DWORD share = 0;
+  DWORD create = 0;
   char buf[MAX_PATH] = "";
 
   jsize total = JvGetStringUTFRegion(path, 0, path->length(), buf);
@@ -82,37 +91,46 @@
 
   JvAssert((jflags & READ) || (jflags & WRITE));
 
-  if ((jflags & READ) && (jflags & WRITE))
+  if (jflags & READ)
     {
-      access = GENERIC_READ | GENERIC_WRITE;
-      share = 0;
-      if (jflags & APPEND)
-	create = OPEN_ALWAYS;
-      else
-	create = CREATE_ALWAYS;
+      access |= GENERIC_READ;
+      share |= FILE_SHARE_READ;
+      create = OPEN_EXISTING;
     }
-  else if(jflags & READ)
-    access = GENERIC_READ;
-  else
+  if (jflags & WRITE)
+    {
+      access |= GENERIC_WRITE;
+      share |= FILE_SHARE_WRITE;
+      create = OPEN_ALWAYS;
+    }
+  if (jflags & EXCL)
     {
-      access = GENERIC_WRITE;
-      share = 0;
-      if (jflags & APPEND)
-	create = OPEN_ALWAYS;
-      else
-        create = CREATE_ALWAYS;
+      create = CREATE_NEW;
     }
 
-  handle = CreateFile(buf, access, share, NULL, create, 0, NULL);
+  h = CreateFile(buf, access, share, NULL, create, 0, NULL);
+
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      DWORD errnum = GetLastError ();
+      java::lang::StringBuffer *msg = new java::lang::StringBuffer (path);
+      msg->append ((jchar)':');
+      msg->append ((jchar)' ');
+      msg->append (winerr (errnum));
+      JvThrow (new FileNotFoundException (msg->toString()));
+    }
 
-  if (handle == INVALID_HANDLE_VALUE)
+  if (jflags & APPEND)
     {
-      char msg[MAX_PATH + 1000];
-      sprintf (msg, "%s: %s", buf, winerr ());
-      JvThrow (new FileNotFoundException (JvNewStringLatin1 (msg)));
+      if (SetFilePointer (h, 0, 0, FILE_END) == -1)
+	{
+	  DWORD errnum = GetLastError ();
+	  CloseHandle (h);
+	  JvThrow (new IOException (winerr (errnum)));
+	}
     }
 
-  return (jint)handle;
+  return reinterpret_cast<gnu::gcj::RawData *> (h);
 }
 
 void
@@ -121,19 +139,21 @@
   DWORD bytesWritten;
   jbyte buf = (jbyte)b;
 
-  if (WriteFile ((HANDLE)fd, &buf, 1, &bytesWritten, NULL))
+  if (WriteFile (reinterpret_cast<HANDLE> (handle),
+      &buf, 1, &bytesWritten, NULL))
     {
       if (java::lang::Thread::interrupted())
         {
-          InterruptedIOException *iioe = new InterruptedIOException (JvNewStringLatin1 ("write interrupted"));
+          InterruptedIOException *iioe = new InterruptedIOException (
+	    JvNewStringLatin1 ("write interrupted"));
           iioe->bytesTransferred = bytesWritten;
           JvThrow (iioe);
         }
       if (bytesWritten != 1)
-        JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+        JvThrow (new IOException (winerr (GetLastError ())));
     }
   else
-    JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+    JvThrow (new IOException (winerr (GetLastError ())));
   // FIXME: loop until bytesWritten == 1
 }
 
@@ -147,27 +167,29 @@
 
   jbyte *buf = elements (b) + offset;
   DWORD bytesWritten;
-  if (WriteFile ((HANDLE)fd, buf, len, &bytesWritten, NULL))
+  if (WriteFile (reinterpret_cast<HANDLE> (handle),
+      buf, len, &bytesWritten, NULL))
     {
       if (java::lang::Thread::interrupted())
         {
-          InterruptedIOException *iioe = new InterruptedIOException (JvNewStringLatin1 ("write interrupted"));
+          InterruptedIOException *iioe = new InterruptedIOException (
+	    JvNewStringLatin1 ("write interrupted"));
           iioe->bytesTransferred = bytesWritten;
           JvThrow (iioe);
         }
     }
   else
-    JvThrow(new IOException (JvNewStringLatin1 (winerr ())));
+    JvThrow(new IOException (winerr (GetLastError ())));
   // FIXME: loop until bytesWritten == len
 }
 
 void
 java::io::FileDescriptor::close (void)
 {
-  HANDLE save = (HANDLE)fd;
-  fd = (jint)INVALID_HANDLE_VALUE;
+  HANDLE save = reinterpret_cast<HANDLE> (handle);
+  handle = reinterpret_cast<gnu::gcj::RawData *> (INVALID_HANDLE_VALUE);
   if (! CloseHandle (save))
-    JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+    JvThrow (new IOException (winerr (GetLastError ())));
 }
 
 jint
@@ -182,9 +204,11 @@
     JvThrow (new EOFException);
 
   LONG high = pos >> 32;
-  DWORD low = SetFilePointer ((HANDLE)fd, (DWORD)(0xffffffff & pos), &high, whence == SET ? FILE_BEGIN : FILE_CURRENT);
+  DWORD low = pos & 0xffffffff;
+  low = SetFilePointer (reinterpret_cast<HANDLE> (handle),
+    low, &high, whence == SET ? FILE_BEGIN : FILE_CURRENT);
   if ((low == 0xffffffff) && (GetLastError () != NO_ERROR))
-    JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+    JvThrow (new IOException (winerr (GetLastError ())));
   return low;
 }
 
@@ -192,9 +216,10 @@
 java::io::FileDescriptor::getFilePointer(void)
 {
   LONG high = 0;
-  DWORD low = SetFilePointer ((HANDLE)fd, 0, &high, FILE_CURRENT);
+  DWORD low = SetFilePointer (
+    reinterpret_cast<HANDLE> (handle), 0, &high, FILE_CURRENT);
   if ((low == 0xffffffff) && (GetLastError() != NO_ERROR))
-    JvThrow(new IOException (JvNewStringLatin1 (winerr ())));
+    JvThrow(new IOException (winerr (GetLastError ())));
   return (((jlong)high) << 32L) | (jlong)low;
 }
 
@@ -204,7 +229,7 @@
   DWORD high;
   DWORD low;
 
-  low = GetFileSize ((HANDLE)fd, &high);
+  low = GetFileSize (reinterpret_cast<HANDLE> (handle), &high);
   // FIXME: Error checking
   return (((jlong)high) << 32L) | (jlong)low;
 }
@@ -215,8 +240,8 @@
   CHAR buf;
   DWORD read;
 
-  if (! ReadFile ((HANDLE)fd, &buf, 1, &read, NULL))
-    JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+  if (! ReadFile (reinterpret_cast<HANDLE> (handle), &buf, 1, &read, NULL))
+    JvThrow (new IOException (winerr (GetLastError ())));
   if (! read)
     return -1;
   else
@@ -236,8 +261,8 @@
   jbyte *bytes = elements (buffer) + offset;
 
   DWORD read;
-  if (! ReadFile((HANDLE)fd, bytes, count, &read, NULL))
-    JvThrow (new IOException (JvNewStringLatin1 (winerr ())));
+  if (! ReadFile(reinterpret_cast<HANDLE> (handle), bytes, count, &read, NULL))
+    JvThrow (new IOException (winerr (GetLastError ())));
 
   return (jint)read;
 }
Index: java/lang/natPosixProcess.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natPosixProcess.cc,v
retrieving revision 1.6
diff -u -r1.6 natPosixProcess.cc
--- natPosixProcess.cc	2000/03/07 19:55:26	1.6
+++ natPosixProcess.cc	2000/04/14 18:34:04
@@ -152,9 +152,12 @@
   // We create the streams before forking.  Otherwise if we had an
   // error while creating the streams we would have run the child with
   // no way to communicate with it.
-  errorStream = new FileInputStream (new FileDescriptor (errp[0]));
-  inputStream = new FileInputStream (new FileDescriptor (inp[0]));
-  outputStream = new FileOutputStream (new FileDescriptor (outp[1]));
+  errorStream = new FileInputStream (new FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (errp[0])));
+  inputStream = new FileInputStream (new FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (inp[0])));
+  outputStream = new FileOutputStream (new FileDescriptor (
+    reinterpret_cast<gnu::gcj::RawData *> (outp[0])));
 
   // We don't use vfork() because that would cause the local
   // environment to be set by the child.
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.19
diff -u -r1.19 natPlainDatagramSocketImpl.cc
--- natPlainDatagramSocketImpl.cc	2000/03/15 22:03:19	1.19
+++ natPlainDatagramSocketImpl.cc	2000/04/14 18:34:04
@@ -170,7 +170,7 @@
       JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
     }
   fnum = sock;
-  fd = new java::io::FileDescriptor (sock);
+  fd = new java::io::FileDescriptor (reinterpret_cast<gnu::gcj::RawData *> (sock));
 }
 
 void
@@ -304,6 +304,7 @@
   jbyte *dbytes = elements (p->getData());
   ssize_t retlen = 0;
 
+#ifdef HAVE_SELECT
   // Do timeouts via select since SO_RCVTIMEO is not always available.
   if (timeout > 0)
     {
@@ -319,6 +320,7 @@
       else if (retval == 0)
 	JvThrow (new java::io::InterruptedIOException ());
     }
+#endif
 
   retlen =
     ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.18
diff -u -r1.18 natPlainSocketImpl.cc
--- natPlainSocketImpl.cc	2000/03/15 22:03:19	1.18
+++ natPlainSocketImpl.cc	2000/04/14 18:34:05
@@ -124,7 +124,7 @@
       JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
     }
   fnum = sock;
-  fd = new java::io::FileDescriptor (sock);
+  fd = new java::io::FileDescriptor (reinterpret_cast<gnu::gcj::RawData *> (sock));
 }
 
 void
@@ -239,6 +239,7 @@
   socklen_t addrlen = sizeof(u);
   int new_socket = 0; 
 
+#ifdef HAVE_SELECT
   // Do timeouts via select since SO_RCVTIMEO is not always available.
   if (timeout > 0)
     {
@@ -255,6 +256,7 @@
 	JvThrow (new java::io::InterruptedIOException (
 	         JvNewStringUTF("Accept timed out")));
     }
+#endif
 
   new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
   if (new_socket < 0)
@@ -281,7 +283,7 @@
   s->localport = localport;
   s->address = new InetAddress (raddr, NULL);
   s->port = rport;
-  s->fd = new java::io::FileDescriptor (new_socket);
+  s->fd = new java::io::FileDescriptor (reinterpret_cast<gnu::gcj::RawData *> (new_socket));
   return;
  error:
   char* strerr = strerror (errno);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]