Patch: java.net -vs- errno
Tom Tromey
tromey@cygnus.com
Wed Aug 9 16:53:00 GMT 2000
I noticed by chance that some code in java.net will throw an exception
whose text is based on `errno' even when errnot has not been set.
Warren, is this patch ok with you?
2000-08-09 Tom Tromey <tromey@cygnus.com>
* java/net/natPlainSocketImpl.cc (bind): Don't go to error case
when errno not set.
(connect): Likewise.
(accept): Likewise.
(getOption): Likewise.
* java/net/natPlainDatagramSocketImpl.cc (bind): Don't go to error
case when errno not set.
(peek): Likewise.
(send): Likewise.
(receive): Likewise.
(mcastGrp): Likewise.
(setOption): Likewise.
(getOption): Likewise.
Tom
Index: java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.20
diff -u -r1.20 natPlainDatagramSocketImpl.cc
--- natPlainDatagramSocketImpl.cc 2000/08/02 21:54:04 1.20
+++ natPlainDatagramSocketImpl.cc 2000/08/09 23:51:43
@@ -199,7 +199,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
+
if (::bind (fnum, ptr, len) == 0)
{
socklen_t addrlen = sizeof(u);
@@ -245,7 +246,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
+
i->address = raddr;
return rport;
error:
@@ -281,7 +283,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
+
if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
return;
error:
@@ -337,7 +340,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
+
p->setAddress (new InetAddress (raddr, NULL));
p->setPort (rport);
p->setLength ((jint) retlen);
@@ -412,7 +416,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
+
if (::setsockopt (fnum, level, opname, ptr, len) == 0)
return;
error:
@@ -507,7 +512,9 @@
}
#endif
else
- goto error;
+ throw
+ new java::net::SocketException (JvNewStringUTF ("invalid length"));
+
if (::setsockopt (fnum, level, opname, ptr, len) != 0)
goto error;
return;
@@ -576,7 +583,7 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.19
diff -u -r1.19 natPlainSocketImpl.cc
--- natPlainSocketImpl.cc 2000/08/02 21:54:04 1.19
+++ natPlainSocketImpl.cc 2000/08/09 23:51:43
@@ -153,7 +153,7 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
// Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
@@ -201,17 +201,20 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
+
if (::connect (fnum, ptr, len) != 0)
goto error;
address = host;
port = rport;
// A bind may not have been done on this socket; if so, set localport now.
if (localport == 0)
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
+ {
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
+ localport = ntohs (u.address.sin_port);
+ else
+ goto error;
+ }
return;
error:
char* strerr = strerror (errno);
@@ -272,7 +275,8 @@
}
#endif
else
- goto error;
+ throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
+
s->fnum = new_socket;
s->localport = localport;
s->address = new InetAddress (raddr, NULL);
@@ -445,7 +449,8 @@
}
#endif
else
- goto error;
+ throw
+ new java::net::SocketException (JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;
More information about the Java-patches
mailing list