[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190823100921.GD12092@stefanha-x1.localdomain>
Date: Fri, 23 Aug 2019 11:09:21 +0100
From: Stefan Hajnoczi <stefanha@...hat.com>
To: Stefano Garzarella <sgarzare@...hat.com>
Cc: netdev@...r.kernel.org, kvm@...r.kernel.org,
Dexuan Cui <decui@...rosoft.com>,
virtualization@...ts.linux-foundation.org,
"David S. Miller" <davem@...emloft.net>,
Jorgen Hansen <jhansen@...are.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 11/11] vsock_test: wait for the remote to close the
connection
On Thu, Aug 22, 2019 at 11:15:46AM +0200, Stefano Garzarella wrote:
> 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()?
Oops, you're right. There are no other blocking calls in this function
so the existing patch is fine.
Thanks,
Stefan
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists