aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/Socket.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net/Socket.java')
-rw-r--r--libjava/java/net/Socket.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index 43c6f3c..714a958 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -488,6 +488,9 @@ public class Socket
*/
public InetAddress getLocalAddress()
{
+ if (! isBound())
+ return null;
+
InetAddress addr = null;
try
@@ -523,12 +526,11 @@ public class Socket
public int getPort()
{
if (! isConnected())
- return 0;
+ return -1;
try
{
- if (getImpl() != null)
- return getImpl().getPort();
+ return getImpl().getPort();
}
catch (SocketException e)
{
@@ -1155,6 +1157,9 @@ public class Socket
*/
public void setReuseAddress(boolean reuseAddress) throws SocketException
{
+ if (isClosed())
+ throw new SocketException("socket is closed");
+
getImpl().setOption(SocketOptions.SO_REUSEADDR,
Boolean.valueOf(reuseAddress));
}
@@ -1217,6 +1222,9 @@ public class Socket
{
try
{
+ if (getImpl() == null)
+ return false;
+
return getImpl().getInetAddress() != null;
}
catch (SocketException e)