How to read / write from / to the SOCK_SEQPACKET socket?

I am trying to use the 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 returns -1 from recvmsg and loops forever. Nowhere in manpages is there a reference to which functions SOCK_SEQPACKET sockets should be used, for example, I'm not quite sure if recvmsg is even the right function.

+4
source share
2 answers

recvmsg()returns -1 if an error occurs - errnowill be set to the error number.

Read here: http://pubs.opengroup.org/onlinepubs/009695399/functions/recvmsg.html

+1
source

SOCK_SEQPACKET , , - .

+1

All Articles