[PATCHES] messaging iov / recvfrom

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue May 27 03:40:23 MDT 2014


On Tue, May 27, 2014 at 11:35:05AM +0200, Andreas Schneider wrote:
> On Tuesday 27 May 2014 10:27:52 you wrote:
> > On Tue, May 27, 2014 at 09:51:10AM +0200, Andreas Schneider wrote:
> > > On Monday 26 May 2014 17:07:44 Michael Adam wrote:
> > > > Oops, there was a bug in the first patch.
> > > > Sorry for posting prematurely...
> > > > Attaching a fixed version.
> > > > 
> > > > diff --git a/source3/lib/unix_msg/unix_msg.c
> > > > b/source3/lib/unix_msg/unix_msg.c index 956e3a3..bcabd28 100644
> > > > --- a/source3/lib/unix_msg/unix_msg.c
> > > > +++ b/source3/lib/unix_msg/unix_msg.c
> > > > @@ -233,8 +233,22 @@ static void unix_dgram_recv_handler(struct
> > > > poll_watch
> > > > *w, int fd, short events,>
> > > > 
> > > >  {
> > > >  
> > > >  	struct unix_dgram_ctx *ctx = (struct unix_dgram_ctx *)private_data;
> > > >  	ssize_t received;
> > > > 
> > > > +	struct msghdr msg;
> > > > +	struct iovec iov;
> > > > +
> > > > +	iov = (struct iovec) {
> > > > +		.iov_base = (void *)ctx->recv_buf,
> > > > +		.iov_len = ctx->max_msg,
> > > > +	};
> > > > +
> > > 
> > > Please use ZERO_STRUCT(msg) here!
> > 
> > Why? This adds an additional call to memset. This construct
> > zeros out everything that is not explicitly initialized
> > anyway. So it is equivalent to a ZERO_STRUCT(msg) and two
> > explicit assignments and gives the compiler the chance to
> > use more efficient instructions.
> 
> The msghdr structure is not the same on all platforms! The memset would zero 
> it correctly on all platforms. If you want to have it this way, then we need 
> configure to check for it and then you need to guard it with

Hmm. From my understanding of this C statement it does
initialize the whole "msg" to 0 and moreover initializes the
explicitly mentioned struct members to their values. So it
is fully equivalent to 

	ZERO_STRUCT(msg);
	msg.iov_base = (void *)ctx->recv_buf;
	msg.iov_len = ctx->max_msg;

with the additional bonus point that it can be more
efficient.

What am I missing here?

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de


More information about the samba-technical mailing list