Commit 84d5fb97 authored by Filippo Storniolo's avatar Filippo Storniolo Committed by David S. Miller

test/vsock: refactor vsock_accept

This is a preliminary patch to introduce SOCK_STREAM bind connect test.
vsock_accept() is split into vsock_listen() and vsock_accept().
Co-developed-by: default avatarLuigi Leonardi <luigi.leonardi@outlook.com>
Signed-off-by: default avatarLuigi Leonardi <luigi.leonardi@outlook.com>
Signed-off-by: default avatarFilippo Storniolo <f.storniolo95@gmail.com>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bfada5a7
...@@ -136,11 +136,8 @@ int vsock_seqpacket_connect(unsigned int cid, unsigned int port) ...@@ -136,11 +136,8 @@ int vsock_seqpacket_connect(unsigned int cid, unsigned int port)
return vsock_connect(cid, port, SOCK_SEQPACKET); return vsock_connect(cid, port, SOCK_SEQPACKET);
} }
/* Listen on <cid, port> and return the first incoming connection. The remote /* Listen on <cid, port> and return the file descriptor. */
* address is stored to clientaddrp. clientaddrp may be NULL. static int vsock_listen(unsigned int cid, unsigned int port, int type)
*/
static int vsock_accept(unsigned int cid, unsigned int port,
struct sockaddr_vm *clientaddrp, int type)
{ {
union { union {
struct sockaddr sa; struct sockaddr sa;
...@@ -152,14 +149,7 @@ static int vsock_accept(unsigned int cid, unsigned int port, ...@@ -152,14 +149,7 @@ static int vsock_accept(unsigned int cid, unsigned int port,
.svm_cid = cid, .svm_cid = cid,
}, },
}; };
union {
struct sockaddr sa;
struct sockaddr_vm svm;
} clientaddr;
socklen_t clientaddr_len = sizeof(clientaddr.svm);
int fd; int fd;
int client_fd;
int old_errno;
fd = socket(AF_VSOCK, type, 0); fd = socket(AF_VSOCK, type, 0);
if (fd < 0) { if (fd < 0) {
...@@ -177,6 +167,24 @@ static int vsock_accept(unsigned int cid, unsigned int port, ...@@ -177,6 +167,24 @@ static int vsock_accept(unsigned int cid, unsigned int port,
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return fd;
}
/* Listen on <cid, port> and return the first incoming connection. The remote
* address is stored to clientaddrp. clientaddrp may be NULL.
*/
static int vsock_accept(unsigned int cid, unsigned int port,
struct sockaddr_vm *clientaddrp, int type)
{
union {
struct sockaddr sa;
struct sockaddr_vm svm;
} clientaddr;
socklen_t clientaddr_len = sizeof(clientaddr.svm);
int fd, client_fd, old_errno;
fd = vsock_listen(cid, port, type);
control_writeln("LISTENING"); control_writeln("LISTENING");
timeout_begin(TIMEOUT); timeout_begin(TIMEOUT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment