[sane-devel] [PATCH v2 12/14] net, call WSAStartup on win32

Ruediger Meier sweet_f_a at gmx.de
Thu Jan 26 12:01:00 UTC 2012


On Tuesday 24 January 2012, Chris Bagwell wrote:
> On Mon, Jan 23, 2012 at 5:05 PM, Ruediger Meier <sweet_f_a at gmx.de> 
wrote:
> > From: Ruediger Meier <ruediger.meier at ga-group.nl>
> >
> > We have to do this on win32 before doing winsock2 stuff. It affects
> > the whole application so don't know wheather it's right to startup
> > and clean it here within the net backend.
>
> Hmm, I wonder if the net.c backend can make more use of functions
> defined sanei_tcp.c?  I've added the same logic there to open and
> close for use by TCP sockets in epson2 backend.  Maybe the patch with
> net_read() and net_write() could make use of something there as well?

Generally I'd also like to re-use code to avoid duplicates but here I'm 
not happy with sanei_tcp/udp because of several reasons. 

1. sanei_tcp/udp does not support ipv6
2. sanei_tcp_read() is IMO broken since 581b94fb.
3. Most socket stuff is the same for udp and tcp so sanei_[tcp|udp] are   
   IMO doomed anyway.

Also switching to these global helpers would mix my win32-port changes 
with generic refactoring and increases the risk that anything I do 
could affect current bahavior.

Nevertheless I'd really like to help fixing and cleaning up network 
stuff in separate patch-sets later. This would probably make even more 
backends portable (and ipv6 ready!).

For now I hope it's ok to commit my net.c changes as they are.
I've re-rolled them according to you other comments. Please pull from my 
private clone
git://github.com/rudimeier/sane-backends.git
branch win32/net-v3

or I can also post it again on the list if wanted.

cu,
Rudi

> Chris
>
> > ---
> >  backend/net.c |   15 +++++++++++++++
> >  1 files changed, 15 insertions(+), 0 deletions(-)
> >
> > diff --git a/backend/net.c b/backend/net.c
> > index 0cd7f51..228bd59 100644
> > --- a/backend/net.c
> > +++ b/backend/net.c
> > @@ -1016,6 +1016,18 @@ sane_init (SANE_Int * version_code,
> > SANE_Auth_Callback authorize) DBG (3, "sane_init: Client has little
> > endian byte order\n"); }
> >
> > +#ifdef _WIN32
> > +    {
> > +      /* no much fun on win32 without WSAStartup but is this the
> > right place? */ +      WSADATA data;
> > +      int wsa_err = WSAStartup( MAKEWORD(2, 2), &data) != 0;
> > +      if ( wsa_err != 0 )
> > +       {
> > +         DBG (1, "sane_init: WSAStartup failed with error %d\n",
> > wsa_err ); +       }
> > +    }
> > +#endif
> > +
> >  #ifndef NET_USES_AF_INDEP
> >   DBG (2, "sane_init: determining sane service port\n");
> >   serv = getservbyname ("sane-port", "tcp");
> > @@ -1196,6 +1208,9 @@ sane_exit (void)
> >        }
> >       free (devlist);
> >     }
> > +#ifdef _WIN32
> > +  WSACleanup();
> > +#endif
> >   DBG (3, "sane_exit: finished.\n");
> >  }
> >
> > --
> > 1.7.6.1
> >
> >
> > --
> > sane-devel mailing list: sane-devel at lists.alioth.debian.org
> > http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
> > Unsubscribe: Send mail with subject "unsubscribe your_password"
> >             to sane-devel-request at lists.alioth.debian.org





More information about the sane-devel mailing list