You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2016/07/20 20:10:20 UTC

[jira] [Comment Edited] (THRIFT-2156) TServerSocket::listen() is throwing exceptions with misleading information

    [ https://issues.apache.org/jira/browse/THRIFT-2156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15386530#comment-15386530 ] 

Jens Geyer edited comment on THRIFT-2156 at 7/20/16 8:10 PM:
-------------------------------------------------------------

{code}
char port[sizeof("65535")];
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
snprintf(port, sizeof("65535"), "%d", port_);
{code}

why not

{code}
const size_t bufsize = sizeof("65535");
char port[bufsize];
snprintf(port, bufsize, "%d", port_);

std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
{code}

seems less prone to error and less confusing to me.
I have not tested this, so it may not even compile.


was (Author: jensg):
{code}
char port[sizeof("65535")];
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
snprintf(port, sizeof("65535"), "%d", port_);
{code}

why not

{code}
const size_t bufsize = sizeof("65535");
char port[bufsize];
snprintf(port, bufsize, "%d", port_);

std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
{code}

seems less prone to error to me.
I have not tested this, so it may not even compile.

> TServerSocket::listen() is throwing exceptions with misleading information
> --------------------------------------------------------------------------
>
>                 Key: THRIFT-2156
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2156
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.9
>            Reporter: Frank Meerkoetter
>            Assignee: James E. King, III
>            Priority: Minor
>         Attachments: errno_copy.patch
>
>
> Due to a problem with bind() an exception was thrown.
> The text was:
> "Could not bind: Transport endpoint is not connected"
> which doesn't make sense.
> It turned out that errno had been overwritten.
> The correct text would have been:
> "Could not bind: Address already in use"



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)