Skip to content

Allow SOCK_SEQPACKET and other socket types.  #28

Description

@eriede

Thank you for the great library. Could I suggest a small improvement, which would allow any native OS sock types to be passed in from java? Something like the following could work:

In UnixDomainSocket.c, could I suggest changing:
s = socket(PF_UNIX, SOCK_TYPE(jSocketType), 0);
to:
s = socket(PF_UNIX, jSocketType, 0);
This would allow SOCK_SEQPACKET to be specified.

This would allow any sock type to be passed to the os.

To maintain compatibility with existing impls and OS's, you could detect and populate the type constants at compile and classload times:
jint Java_com_etsy_net_UnixDomainSocket_nativeSockTypeVal(jstring val){
#ifdef SOCK_STREAM
if(0==strcmp(val,"SOCK_STREAM")) return SOCK_STREAM;
#endif
#ifdef SOCK_DGRAM
if(0==strcmp(val,"SOCK_DGRAM")) return SOCK_DGRAM;
#endif
#ifdef SOCK_SEQPACKET
if(0==strcmp(val,"SOCK_SEQPACKET")) return SOCK_SEQPACKET;
#endif
// etc.... for different known enums
return -1;
}

//Add a quick static wrapper in UnixDomainSocket.java
//then in JUDS.java
static{
SOCK_STREAM = UnixDomainSocket.SockTypeVal("SOCK_STREAM");
SOCK_DGRAM = UnixDomainSocket.SockTypeVal("SOCK_DGRAM");
SOCK_SEQPACKET = UnixDomainSocket.SockTypeVal("SOCK_SEQPACKET");
//etc...
};

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions