This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

Re: FYI: Patch: java.net: socket stuff


Hi Michael,

>> Based on your convictions, what would be your opinion of replacing
>> this:
>> 
>>   if (isClosed()) 
>>     throw new SocketException("socket is closed"); 
>> 
>> ...with this:
>> 
>>   if (isClosed()) 
>>     throw new SocketException(SOCKET_CLOSED_TEXT); 
>> 
>> where SOCKET_CLOSED_TEXT is:
>> 
>> private static final String SOCKET_CLOSED_TEXT = "socket is closed";
>
>Okay, okay, okay. You cooked me. 

:)

>Please provide a patch for this. I will accept it and Tom will have
>nothing against it too I assume.

>Personally I think the name for constant should be SOCKET_CLOSE. Thats
>clear enough.

I ran a few tests with this on the i686-pc-linux-gnu native compiler.
Just let me know and I'll commit it....

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/

ChangeLog
2003-11-26  Mohan Embar  <gnustuff@thisiscool.com>

	* java/net/Socket.java (lots): Consolidated "socket is closed"
	SocketException text into a single string constant.

Index: java/net/Socket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/Socket.java,v
retrieving revision 1.31
diff -u -2 -r1.31 Socket.java
--- java/net/Socket.java	26 Nov 2003 12:45:21 -0000	1.31
+++ java/net/Socket.java	26 Nov 2003 13:12:00 -0000
@@ -74,4 +74,9 @@
    */
   static SocketImplFactory factory;
+  
+  /**
+   * SocketException text which is used in several places.
+   */
+  private static final String SOCKET_CLOSED = "socket is closed";
 
   /**
@@ -342,5 +347,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
 
     // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
@@ -416,5 +421,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (! (endpoint instanceof InetSocketAddress))
@@ -612,5 +617,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (!isConnected())
@@ -630,5 +635,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (!isConnected())
@@ -650,5 +655,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().setOption(SocketOptions.TCP_NODELAY, new Boolean(on));
@@ -670,5 +675,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object on = getImpl().getOption(SocketOptions.TCP_NODELAY);
@@ -700,5 +705,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (on == true)
@@ -737,5 +742,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object linger = getImpl().getOption(SocketOptions.SO_LINGER);
@@ -760,5 +765,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().sendUrgentData (data);
@@ -777,5 +782,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().setOption(SocketOptions.SO_OOBINLINE, new Boolean(on));
@@ -794,5 +799,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE);
@@ -824,5 +829,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (timeout < 0)
@@ -852,5 +857,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT);
@@ -876,5 +881,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (size <= 0)
@@ -898,5 +903,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
@@ -923,5 +928,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (size <= 0)
@@ -945,5 +950,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
@@ -968,5 +973,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on));
@@ -986,5 +991,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE);
@@ -1004,5 +1009,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().close();
@@ -1079,5 +1084,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().shutdownInput();
@@ -1095,5 +1100,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     getImpl().shutdownOutput();
@@ -1125,5 +1130,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object reuseaddr = getImpl().getOption (SocketOptions.SO_REUSEADDR);
@@ -1163,5 +1168,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     Object obj = getImpl().getOption(SocketOptions.IP_TOS);
@@ -1188,5 +1193,5 @@
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      throw new SocketException(SOCKET_CLOSED);
     
     if (tc < 0 || tc > 255)




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