[reSIProcate] Compiler error in TcpBaseTransport
Daniel Pocock
daniel at pocock.com.au
Thu Dec 5 09:52:06 CST 2013
On 05/12/13 10:39, Dario Bozzali wrote:
>
> Hi all,
>
> I've got head revision of Resiprocate and I tried to compile.
>
> I encountered the following compiler errors (my environment is Visual
> C++ 2005) since size of _sa is not constant.
>
>
>
> 1>.\TcpBaseTransport.cxx(219) : error C2057: expected constant expression
>
> 1>.\TcpBaseTransport.cxx(219) : error C2466: cannot allocate an array
> of constant size 0
>
> 1>.\TcpBaseTransport.cxx(219) : error C2133: '_sa' : unknown size
>
Ok, I had hoped that this would allocate on the stack rather than the
heap. It worked on Linux builds but not on Windows, thanks for pointing
that out.
Using new[] allocates on the heap, maybe it is slower that way
There are various options, like using sizeof(sockaddr_storage) or the
MAX(...) example you give below
We could also modify the anonymous union in Tuple.hxx and give it a
name, then use sizeof() on that. As it is private, there are not too
many references to the members that we would need to change.
Does anybody have any preference on the most portable way of achieving this?
>
>
> I would suggest a change to the code similar to the one that I
> reported below. Or _sa could have the size equal to
> MAX(sizeof(sockaddr_in), sizeof(sockaddr_in6)).
>
> Thank you in advance and kind regards,
>
> Dario.
>
>
>
>
>
> Connection*
>
> TcpBaseTransport::makeOutgoingConnection(const Tuple &dest,
>
> TransportFailure::FailureReason &failReason, int &failSubCode)
>
> {
>
> // attempt to open
>
> Socket sock = InternalTransport::socket( TCP, ipVersion());
>
> // fdset.clear(sock); !kw! removed as part of epoll impl
>
>
>
> if ( sock == INVALID_SOCKET ) // no socket found - try to free one
> up and try again
>
> {
>
> int err = getErrno();
>
> InfoLog (<< "Failed to create a socket " << strerror(err));
>
> error(err);
>
> mConnectionManager.gc(ConnectionManager::MinimumGcAge, 1); //
> free one up
>
>
>
> sock = InternalTransport::socket( TCP, ipVersion());
>
> if ( sock == INVALID_SOCKET )
>
> {
>
> err = getErrno();
>
> WarningLog( << "Error in finding free filedescriptor to use.
> " << strerror(err));
>
> error(err);
>
> failReason = TransportFailure::TransportNoSocket;
>
> failSubCode = err;
>
> return NULL;
>
> }
>
> }
>
>
>
> assert(sock != INVALID_SOCKET);
>
>
>
> DebugLog (<<"Opening new connection to " << dest);
>
> socklen_t len = mTuple.length();
>
> * //char _sa[len];*
>
> * char* _sa = new char[len];*
>
> * sockaddr *sa = reinterpret_cast<sockaddr*>(_sa);*
>
> * mTuple.copySockaddrAnyPort(sa);*
>
> * //if(::bind(sock, sa, len) != 0)*
>
> * int ret = ::bind(sock, sa, len);*
>
> * delete [] _sa;*
>
> * sa = NULL;*
>
> * if (ret != 0)*
>
> {
>
> WarningLog( << "Error in binding to source interface address. "
> << strerror(errno));
>
> failReason = TransportFailure::Failure;
>
> failSubCode = errno;
>
> return NULL;
>
> }
>
> makeSocketNonBlocking(sock);
>
> if (mSocketFunc)
>
> {
>
> mSocketFunc(sock, transport(), __FILE__, __LINE__);
>
> }
>
> const sockaddr& servaddr = dest.getSockaddr();
>
> * //int ret = connect( sock, &servaddr, dest.length() );*
>
> * ret = connect( sock, &servaddr, dest.length() );*
>
>
>
> // See Chapter 15.3 of Stevens, Unix Network Programming Vol. 1 2nd
> Edition
>
> if (ret == SOCKET_ERROR)
>
> {
>
> int err = getErrno();
>
>
>
> switch (err)
>
> {
>
> case EINPROGRESS:
>
> case EWOULDBLOCK:
>
> break;
>
> default:
>
> {
>
> // !jf! this has failed
>
> InfoLog( << "Error on TCP connect to " << dest << ",
> err=" << err << ": " << strerror(err));
>
> error(err);
>
> //fdset.clear(sock);
>
> closeSocket(sock);
>
> failReason = TransportFailure::TransportBadConnect;
>
> failSubCode = err;
>
> return NULL;
>
> }
>
> }
>
> }
>
>
>
> // This will add the connection to the manager
>
> Connection *conn = createConnection(dest, sock, false);
>
> assert(conn);
>
> conn->mRequestPostConnectSocketFuncCall = true;
>
> returnconn;
>
> }
>
>
>
>
>
>
>
> _______________________________________________
> resiprocate-devel mailing list
> resiprocate-devel at resiprocate.org
> https://list.resiprocate.org/mailman/listinfo/resiprocate-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20131205/f6f90213/attachment.htm>
More information about the resiprocate-devel
mailing list