lkml.org 
[lkml]   [2019]   [Aug]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 11/11] vsock_test: wait for the remote to close the connection
On Tue, Aug 20, 2019 at 09:28:28AM +0100, Stefan Hajnoczi wrote:
> On Thu, Aug 01, 2019 at 05:25:41PM +0200, Stefano Garzarella wrote:
> > +/* Wait for the remote to close the connection */
> > +void vsock_wait_remote_close(int fd)
> > +{
> > + struct epoll_event ev;
> > + int epollfd, nfds;
> > +
> > + epollfd = epoll_create1(0);
> > + if (epollfd == -1) {
> > + perror("epoll_create1");
> > + exit(EXIT_FAILURE);
> > + }
> > +
> > + ev.events = EPOLLRDHUP | EPOLLHUP;
> > + ev.data.fd = fd;
> > + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
> > + perror("epoll_ctl");
> > + exit(EXIT_FAILURE);
> > + }
> > +
> > + nfds = epoll_wait(epollfd, &ev, 1, TIMEOUT * 1000);
> > + if (nfds == -1) {
> > + perror("epoll_wait");
> > + exit(EXIT_FAILURE);
> > + }
> > +
> > + if (nfds == 0) {
> > + fprintf(stderr, "epoll_wait timed out\n");
> > + exit(EXIT_FAILURE);
> > + }
> > +
> > + assert(nfds == 1);
> > + assert(ev.events & (EPOLLRDHUP | EPOLLHUP));
> > + assert(ev.data.fd == fd);
> > +
> > + close(epollfd);
> > +}
>
> Please use timeout_begin()/timeout_end() so that the test cannot hang.
>

I used the TIMEOUT macro in the epoll_wait() to avoid the hang.
Do you think is better to use the timeout_begin()/timeout_end()?
In this case, should I remove the timeout in the epoll_wait()?

> > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
> > index 64adf45501ca..a664675bec5a 100644
> > --- a/tools/testing/vsock/vsock_test.c
> > +++ b/tools/testing/vsock/vsock_test.c
> > @@ -84,6 +84,11 @@ static void test_stream_client_close_server(const struct test_opts *opts)
> >
> > control_expectln("CLOSED");
> >
> > + /* Wait for the remote to close the connection, before check
> > + * -EPIPE error on send.
> > + */
> > + vsock_wait_remote_close(fd);
>
> Is control_expectln("CLOSED") still necessary now that we're waiting for
> the poll event? The control message was an attempt to wait until the
> other side closed the socket.

Right, I'll remove it in the v3

Thanks,
Stefano

\
 
 \ /
  Last update: 2019-08-22 11:16    [W:0.067 / U:2.728 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site