[PATCHES] messaging iov / recvfrom
Andreas Schneider
asn at samba.org
Tue May 27 03:35:05 MDT 2014
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
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
As recvmsg also fills out msg.msg_name normally, I think it needs to be set to
NULL too and msg.msg_namelen = 0.
-- andreas
--
Andreas Schneider GPG-ID: CC014E3D
Samba Team asn at samba.org
www.samba.org
More information about the samba-technical
mailing list