[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] [PATCH 07/11] nbd-server: do not lose connections



On Fri, Jun 22, 2012 at 01:42:19AM +0400, Dmitry V. Levin wrote:
> When select reports that more than one connection is ready to be
> accepted, handle them all instead of losing all of them but one.

Mm. I might be mistaken, but I was under the impression that if you do
it that way, select() will just return immediately next time and tell
you that there's another socket ready for reading.

But, granted, this might be a slight bit faster, especially if you're
exporting loads of files.

> Signed-off-by: Dmitry V. Levin <ldv@...1147...>
> ---
>  nbd-server.c |   16 ++++++++--------
>  1 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/nbd-server.c b/nbd-server.c
> index d8ac693..cd8fdb9 100644
> --- a/nbd-server.c
> +++ b/nbd-server.c
> @@ -2263,15 +2263,14 @@ int serveloop(GArray* servers) {
>  		max=modernsock>max?modernsock:max;
>  	}
>  	for(;;) {
> -		CLIENT *client = NULL;
> -
>  		memcpy(&rset, &mset, sizeof(fd_set));
>  		if(select(max+1, &rset, NULL, NULL, NULL)>0) {
> -			int net = -1;
> -			SERVER* serve=NULL;
> +			int net;
>  
>  			DEBUG("accept, ");
>  			if(modernsock >= 0 && FD_ISSET(modernsock, &rset)) {
> +				CLIENT *client;
> +
>  				if((net=accept(modernsock, (struct sockaddr *) &addrin, &addrinlen)) < 0) {
>  					err_nonfatal("accept: %m");
>  					continue;
> @@ -2282,19 +2281,20 @@ int serveloop(GArray* servers) {
>  					close(net);
>  					continue;
>  				}
> -				serve = client->server;
> +				handle_connection(servers, net, client->server, client);
>  			}
> -			for(i=0; i < servers->len && net < 0; i++) {
> +			for(i=0; i < servers->len; i++) {
> +				SERVER *serve;
> +
>  				serve=&(g_array_index(servers, SERVER, i));
>  				if(FD_ISSET(serve->socket, &rset)) {
>  					if ((net=accept(serve->socket, (struct sockaddr *) &addrin, &addrinlen)) < 0) {
>  						err_nonfatal("accept: %m");
>  						continue;
>  					}
> +					handle_connection(servers, net, serve, NULL);
>  				}
>  			}
> -			if (net >= 0)
> -				handle_connection(servers, net, serve, client);
>  		}
>  	}
>  }
> -- 
> ldv
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Nbd-general mailing list
> Nbd-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nbd-general
> 

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula:

pi zz a



Reply to: