how to read/write from/to a SOCK_SEQPACKET socket?

Viewed 4324

I try to use a SOCK_SEQPACKET socket with this:

int    rc, len;
int    worker_sd, pass_sd;
char   buffer[80];
struct iovec   iov[1];
struct msghdr  msg;

memset(&msg,   0, sizeof(msg));
memset(iov,    0, sizeof(iov));

iov[0].iov_base = buffer;
iov[0].iov_len  = sizeof(buffer);
msg.msg_iov     = iov;
msg.msg_iovlen  = 1;

if((socket_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) < 0)
{
    perror("server: socket");
    exit -1;
}
memset(&server_address, 0, sizeof(server_address));
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, "/mysocket");

unlink("/mysocket");       
if(bind(socket_fd, (const struct sockaddr *) &server_address, sizeof(server_address)) < 0)
{
    close(socket_fd);
    perror("server: bind error");
    return 1;
}


while(1)
{
    printf("wait for message\n");

    bytes_received = recvmsg(socket_fd, &msg, MSG_WAITALL);


    printf("%d bytes\n", bytes_received);

}

The problem is that the process does not wait but receives -1 from recvmsg and loops forever. Nowhere in the manpages is there any reference what functions shall be used with SOCK_SEQPACKET-style sockets, for example I am not really sure whether recvmsg is even the correct function.

2 Answers
Related