Project

General

Profile

Bug #393 » 0002-fixed-wrong-error-message-in-dcmnet-with-win32.patch

This patch should not be applied directly to the DCMTK! - Jörg Riesmeier, 2013-10-12 12:38

View differences:

dcmnet/libsrc/dul.cc
{
char buf[256];
OFOStringStream stream;
stream << "TCP Initialization Error: " << OFStandard::strerror(errno, buf, sizeof(buf))
stream << "TCP Initialization Error: " << FormatSocketError(GetLastSocketError(), buf, sizeof(buf))
<< ", getpeername failed on socket " << sock << OFStringStream_ends;
OFSTRINGSTREAM_GETOFSTRING(stream, msg)
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
......
do
{
sock = accept((*network)->networkSpecific.TCP.listenSocket, &from, &len);
#ifdef HAVE_WINSOCK_H
} while (sock == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (sock == -1 && errno == EINTR);
#endif
if (sock < 0)
{
char buf[256];
OFOStringStream stream;
stream << "TCP Initialization Error: " << OFStandard::strerror(errno, buf, sizeof(buf))
stream << "TCP Initialization Error: " << FormatSocketError(GetLastSocketError(), buf, sizeof(buf))
<< ", accept failed on socket " << sock << OFStringStream_ends;
OFSTRINGSTREAM_GETOFSTRING(stream, msg)
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
......
{
char buf[256];
OFOStringStream stream;
stream << "TCP Initialization Error: " << OFStandard::strerror(errno, buf, sizeof(buf))
stream << "TCP Initialization Error: " << FormatSocketError(GetLastSocketError(), buf, sizeof(buf))
<< ", setsockopt failed on socket " << sock << OFStringStream_ends;
OFSTRINGSTREAM_GETOFSTRING(stream, msg)
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
#endif
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
}
......
#endif
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf)); // where is corresponding socket call?
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
reuse = 1;
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
#endif
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
/* Find out assigned port number and print it out */
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
#ifdef HAVE_GUSI_H
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
#endif
......
OFString str;
COUT << dumpExtNegList(str, lst) << OFendl;
}
int GetLastSocketError()
{
#ifdef _WIN32
return WSAGetLastError();
#else
return errno;
#endif
}
const char* FormatSocketError(int errnum, char* buf, size_t len)
{
#ifdef _WIN32
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errnum,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf,
len,
NULL);
return buf;
#else
return OFStandard::strerror(errnum, buf, len);
#endif
}
dcmnet/libsrc/dulfsm.cc
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
server.sin_family = AF_INET;
......
timeout.tv_usec = 0;
rc = select(s+1, NULL, &fdSet, NULL, &timeout);
#ifdef HAVE_WINSOCK_H
// save errno for later
int errnum = WSAGetLastError();
#endif
// reset socket to blocking mode
#ifdef HAVE_WINSOCK_H
......
if ((*association)->connection) delete (*association)->connection;
(*association)->connection = NULL;
#ifdef HAVE_WINSOCK_H
// restore errno from "select" above
WSASetLastError(errnum);
#endif
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += " (Timeout)";
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
......
if (rc < 0)
{
#if HAVE_WINSOCK_H
// save errno for later
int errnum = WSAGetLastError();
#endif
// an error other than timeout in non-blocking mode has occured,
// either in connect() or in select().
#ifdef HAVE_WINSOCK_H
......
(*association)->networkState = NETWORK_DISCONNECTED;
if ((*association)->connection) delete (*association)->connection;
(*association)->connection = NULL;
#ifdef HAVE_WINSOCK_H
// restore errno from above "connect"
WSASetLastError(errnum);
#endif
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
} else {
// success - we've opened a TCP transport connection
......
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf)); // ???
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
sockarg.l_onoff = 0;
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
#endif
......
{
char buf[256];
OFString msg = "TCP Initialization Error: ";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
return makeDcmnetCondition(DULC_TCPINITERROR, OF_error, msg.c_str());
}
}
......
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(associateRequest.length + 6)) : 0;
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != associateRequest.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendAssociationRQTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(associateReply.length + 6)) : 0;
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != associateReply.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendAssociationACTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
{
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(pdu.length + 6)) : 0;
} while (nbytes == -1 && errno == EINTR);
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != pdu.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendAssociationRJTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
if (cond.good()) {
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(pdu.length + 6)) : 0;
} while (nbytes == -1 && errno == EINTR);
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != pdu.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendAbortTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
if (cond.good()) {
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(pdu.length + 6)) : 0;
} while (nbytes == -1 && errno == EINTR);
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != pdu.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendReleaseRQTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
if (cond.good()) {
do {
nbytes = (*association)->connection ? (*association)->connection->write((char*)b, size_t(pdu.length + 6)) : 0;
} while (nbytes == -1 && errno == EINTR);
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
if ((unsigned long) nbytes != pdu.length + 6)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: sendReleaseRPTCP";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
do
{
nbytes = (*association)->connection ? (*association)->connection->write((char*)head, size_t(length)) : 0;
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
/* if not all head information was sent, return an error */
if ((unsigned long) nbytes != length)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: writeDataPDU";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
{
nbytes = (*association)->connection ? (*association)->connection->write((char*)pdu->presentationDataValue.data,
size_t(pdu->presentationDataValue.length - 2)) : 0;
#ifdef HAVE_WINSOCK_H
} while (nbytes == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (nbytes == -1 && errno == EINTR);
#endif
/* if not all head information was sent, return an error */
if ((unsigned long) nbytes != pdu->presentationDataValue.length - 2)
{
char buf[256];
OFString msg = "TCP I/O Error (";
msg += OFStandard::strerror(errno, buf, sizeof(buf));
msg += FormatSocketError(GetLastSocketError(), buf, sizeof(buf));
msg += ") occurred in routine: writeDataPDU";
return makeDcmnetCondition(DULC_TCPIOERROR, OF_error, msg.c_str());
}
......
/* data has become available, now call read(). */
bytesRead = connection->read((char*)b, size_t(l));
} while (bytesRead == -1 && errno == EINTR);
#ifdef HAVE_WINSOCK_H
} while (bytesRead == -1 && WSAGetLastError() == WSAEINTR);
#else
} while (bytesRead == -1 && errno == EINTR);
#endif
/* if we actually received data, move the buffer pointer to its own end, update the variable */
/* that determines the end of the first loop, and update the reference parameter return variable */
dcmnet/libsrc/dulpriv.h
PRV_NextPDUType(PRIVATE_ASSOCIATIONKEY ** association,
DUL_BLOCKOPTIONS block, int timeout, unsigned char *type);
int GetLastSocketError();
const char* FormatSocketError(int errnum, char* buf, size_t len);
#endif
    (1-1/1)