Skip to content

Commit 84d5fb9

Browse files
fstorniolodavem330
authored andcommitted
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: Luigi Leonardi <luigi.leonardi@outlook.com> Signed-off-by: Luigi Leonardi <luigi.leonardi@outlook.com> Signed-off-by: Filippo Storniolo <f.storniolo95@gmail.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bfada5a commit 84d5fb9

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tools/testing/vsock/util.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,8 @@ int vsock_seqpacket_connect(unsigned int cid, unsigned int port)
136136
return vsock_connect(cid, port, SOCK_SEQPACKET);
137137
}
138138

139-
/* Listen on <cid, port> and return the first incoming connection. The remote
140-
* address is stored to clientaddrp. clientaddrp may be NULL.
141-
*/
142-
static int vsock_accept(unsigned int cid, unsigned int port,
143-
struct sockaddr_vm *clientaddrp, int type)
139+
/* Listen on <cid, port> and return the file descriptor. */
140+
static int vsock_listen(unsigned int cid, unsigned int port, int type)
144141
{
145142
union {
146143
struct sockaddr sa;
@@ -152,14 +149,7 @@ static int vsock_accept(unsigned int cid, unsigned int port,
152149
.svm_cid = cid,
153150
},
154151
};
155-
union {
156-
struct sockaddr sa;
157-
struct sockaddr_vm svm;
158-
} clientaddr;
159-
socklen_t clientaddr_len = sizeof(clientaddr.svm);
160152
int fd;
161-
int client_fd;
162-
int old_errno;
163153

164154
fd = socket(AF_VSOCK, type, 0);
165155
if (fd < 0) {
@@ -177,6 +167,24 @@ static int vsock_accept(unsigned int cid, unsigned int port,
177167
exit(EXIT_FAILURE);
178168
}
179169

170+
return fd;
171+
}
172+
173+
/* Listen on <cid, port> and return the first incoming connection. The remote
174+
* address is stored to clientaddrp. clientaddrp may be NULL.
175+
*/
176+
static int vsock_accept(unsigned int cid, unsigned int port,
177+
struct sockaddr_vm *clientaddrp, int type)
178+
{
179+
union {
180+
struct sockaddr sa;
181+
struct sockaddr_vm svm;
182+
} clientaddr;
183+
socklen_t clientaddr_len = sizeof(clientaddr.svm);
184+
int fd, client_fd, old_errno;
185+
186+
fd = vsock_listen(cid, port, type);
187+
180188
control_writeln("LISTENING");
181189

182190
timeout_begin(TIMEOUT);

0 commit comments

Comments
 (0)