[PATCHES] messaging iov / recvfrom
Jeremy Allison
jra at samba.org
Thu May 29 13:51:03 MDT 2014
On Tue, May 27, 2014 at 11:40:23AM +0200, Volker Lendecke wrote:
> 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?
Nothing. I'm pretty sure.
These are designated initializers, a C99 feature:
http://www-01.ibm.com/support/knowledgecenter/SSXVZZ_8.0.0/com.ibm.xlcpp8l.doc/language/ref/designators.htm%23DESIGNATORS?lang=en
You patchset is correct :-).
More information about the samba-technical
mailing list