SCTP for Java

David M. Lloyd david.lloyd at redhat.com
Wed Aug 27 19:12:02 PDT 2008


On 08/27/2008 03:00 PM, Florian Weimer wrote:
> * David M. Lloyd:
> 
>> Doing this: UnixSocketChannel.open(String) or similar seems more
>> correct to me.
> 
> You need to do this twice, for SOCK_STREAM and SOCK_DGRAM.
> 
>> If you go the route of using SocketChannel.open(SocketAddress), for
>> example, now you've got instanceof checks for each socket type.  Does
>> this not seem like a so-called "code smell" to you?
> 
> I've written an OO-ish socket abstraction, and I used struct
> sockaddr_storage as the glue between socket addresses and sockets
> (technically, I didn't even have to make the socket address class
> abstract, but I think I still did).  There are some safety issues with
> this approach, though, and maybe OpenJDK needs to support systems
> without struct sockaddr_storage.

I still maintain that it's the wrong solution - SocketAddress is a 
completely empty abstract class.  Empty classes (like marker interfaces) 
add no value that cannot be gained in other, better ways.  The only reason 
it exists is because C has sockaddr, so it seems like a reasonable thing to 
do.  However, if one were to look at sockets afresh, looking at the 
similarities and differences between IP-based socket types and UNIX socket 
types, and designing the classes based on those ideals, I think the answer 
would be vastly different.  Though this ideal is obviously not practical in 
many cases (especially in the case of the JDK), people should still think 
in this way, and then ask themselves, "How can I make what we have today be 
the most like this ideal?", rather than carry on a bad design just because 
that's how it has always been.

- DML



More information about the net-dev mailing list