Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Approach to sin_zero

Reply
Thread Tools

Approach to sin_zero

 
 
Ian Collins
Guest
Posts: n/a
 
      10-10-2012
On 10/10/12 14:47, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Here's a version that uses getaddrinfo:
>
> sock_type cmw::udp_server (uint16_t port)
> {
> ::std:stringstream out;
> out<< port;
>
> addrinfo* res;
> addrinfo hints;
> ::std::memset(&hints, 0, sizeof(hints));


Why do you call memset?

addrinfo hints = {0};

Is more concise.

> hints.ai_family = AF_UNSPEC;
> hints.ai_socktype = SOCK_DGRAM;
> hints.ai_flags = AI_PASSIVE;
>
> int err;
> if ((err = ::getaddrinfo(nullptr
> , out.str().c_str()
> ,&hints
> ,&res
> )) != 0) {
> throw failure("udp_server getaddrinfo: ")<< gai_strerror(err);
> }
>
> sock_type sd = getSocket(SOCK_DGRAM);
> if (::bind(sd, res->ai_addr, res->ai_addrlen)==-1) {
> throw failure("udp_server bind: ")<< GetError();
> }
> return sd;
> }
>
> The unfortunate thing is the change adds over 2,000 bytes
> to an executable. It isn't a big executable and the
> percentage increase is close to 3%. That strikes me as
> excessive. Are there any other alternatives?


Try comp.unix.programmer.

--
Ian Collins
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-10-2012
On 10/10/12 15:06, (E-Mail Removed) wrote:
> On Tuesday, October 9, 2012 9:47:21 PM UTC-4, (unknown) wrote:
>
>>
>> Are there any other alternatives?

>
> Does it work to change
>
> si_me.sin_family = AF_INET;
>
> to
>
> si_me.sin_family = AF_UNSPEC;
>
> in the function I originally posted?
>
> It looks like there are people doing that out there,
> but I couldn't find anything that says it is valid.


Try comp.unix.programmer.
--
Ian Collins
 
Reply With Quote
 
 
 
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      10-10-2012
On Tuesday, October 9, 2012 10:07:55 PM UTC-4, Ian Collins wrote:
>
>
> Why do you call memset?
>
>
>
> addrinfo hints = {0};
>
>
>
> Is more concise.
>


Thanks. I started using that now, but it didn't
affect the size of the executable.


 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      10-12-2012

To go a little further with this ... everything seems
to be working fine on Linux. And if the middle tier is
running on Linux and the front tier on Windows things
work fine. But if both the middle and front tiers are
running on Windows, I get a 10054 -- port unreachable
error. I'm not sure if this indicates a problem in the
networking code that I've been working on. If there is
a problem, the above seems to indicate it is with the
middle tier which is a udp server.

addrinfo* cmw::getaddrinfo_wrapper(char const * node
, int port
, int flags
, int socktype
)
{
::std:stringstream out;
out << port;

addrinfo* res;
addrinfo hints = {0};
hints.ai_flags = flags;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = socktype;

int err;
if ((err = ::getaddrinfo(node
, out.str().c_str()
, &hints
, &res
)) != 0) {
throw failure("Getaddrinfo: ") << gai_strerror(err);
}
return res;
}


sock_type cmw::udp_server (uint16_t port)
{
addrinfo* res = getaddrinfo_wrapper(nullptr
, port
, AI_PASSIVE
, SOCK_DGRAM
);
sock_type sd = getSocket(res->ai_family, SOCK_DGRAM);
if (::bind(sd, res->ai_addr, res->ai_addrlen)==-1) {
throw failure("udp_server bind: ") << GetError();
}
::freeaddrinfo(res);
return sd;
}

Netstat on windows shows this
UDP [::]:55555 *:*

which is the port number I expect it to use.

I guess it could be a Windows problem, but am not
really sure. All of the code is here --
http://webEbenezer.net/build_integration.html
..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Core Exams - Best approach to take? =?Utf-8?B?R2F2aW4=?= MCSE 1 02-02-2006 03:29 PM
Bitplane approach to FIR filter architecture Wiener, Norbert VHDL 4 11-18-2004 02:31 AM
advice needed - what approach for sql access KavvY ASP .Net 1 07-17-2004 08:17 AM
what is a better approach to synthezise synchronous reset on FPGA? valentin tihomirov VHDL 9 04-15-2004 01:41 PM
is smart to use frames approach les ASP .Net 1 07-31-2003 03:49 PM



Advertisments