Cleanup in TS dir (Erik! No binaries in the git! ), added getError() to socket lib, fixed Buffer problems when a Connector is being slow.
This commit is contained in:
parent
9af2bc0d93
commit
07aff5ad16
4 changed files with 44 additions and 16 deletions
|
@ -66,8 +66,8 @@ namespace Buffer{
|
|||
bool doSend(){
|
||||
int r = S.iwrite((char*)lastpointer+currsend, MyBuffer_len-currsend);
|
||||
if (r <= 0){
|
||||
if ((r < 0) && (errno == EWOULDBLOCK)){return false;}
|
||||
Disconnect("Connection closed");
|
||||
if (errno == EWOULDBLOCK){return false;}
|
||||
Disconnect(S.getError());
|
||||
return false;
|
||||
}
|
||||
currsend += r;
|
||||
|
|
Binary file not shown.
|
@ -33,6 +33,11 @@ void Socket::Connection::close(){
|
|||
/// Returns internal socket number.
|
||||
int Socket::Connection::getSocket(){return sock;}
|
||||
|
||||
/// Returns a string describing the last error that occured.
|
||||
/// Simply calls strerror(errno) - not very reliable!
|
||||
/// \todo Improve getError at some point to be more reliable and only report socket errors.
|
||||
std::string Socket::Connection::getError(){return strerror(errno);}
|
||||
|
||||
/// Create a new Unix Socket. This socket will (try to) connect to the given address right away.
|
||||
/// \param address String containing the location of the Unix socket to connect to.
|
||||
/// \param nonblock Whether the socket should be nonblocking. False by default.
|
||||
|
@ -86,7 +91,11 @@ signed int Socket::Connection::ready(){
|
|||
}
|
||||
}
|
||||
if (r == 0){
|
||||
close(); return -1;
|
||||
#if DEBUG >= 4
|
||||
fprintf(stderr, "Socket ready error - socket is closed.\n");
|
||||
#endif
|
||||
close();
|
||||
return -1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
@ -192,7 +201,12 @@ int Socket::Connection::iwrite(void * buffer, int len){
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (r == 0){close();}
|
||||
if (r == 0){
|
||||
#if DEBUG >= 4
|
||||
fprintf(stderr, "Could not iwrite data! Socket is closed.\n");
|
||||
#endif
|
||||
close();
|
||||
}
|
||||
return r;
|
||||
}//Socket::Connection::iwrite
|
||||
|
||||
|
@ -217,7 +231,12 @@ int Socket::Connection::iread(void * buffer, int len){
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (r == 0){close();}
|
||||
if (r == 0){
|
||||
#if DEBUG >= 4
|
||||
fprintf(stderr, "Could not iread data! Socket is closed.\n");
|
||||
#endif
|
||||
close();
|
||||
}
|
||||
return r;
|
||||
}//Socket::Connection::iread
|
||||
|
||||
|
@ -399,7 +418,12 @@ Socket::Connection Socket::Server::accept(bool nonblock){
|
|||
}
|
||||
Socket::Connection tmp(r);
|
||||
if (r < 0){
|
||||
if (errno != EWOULDBLOCK && errno != EAGAIN){close();}
|
||||
if (errno != EWOULDBLOCK && errno != EAGAIN){
|
||||
#if DEBUG >= 1
|
||||
fprintf(stderr, "Error during accept - closing server socket.\n");
|
||||
#endif
|
||||
close();
|
||||
}
|
||||
}else{
|
||||
if (addrinfo.sin6_family == AF_INET6){
|
||||
tmp.remotehost = inet_ntop(AF_INET6, &(addrinfo.sin6_addr), addrconv, INET6_ADDRSTRLEN);
|
||||
|
@ -426,6 +450,9 @@ Socket::Connection Socket::Server::accept(bool nonblock){
|
|||
|
||||
/// Close connection. The internal socket is closed and then set to -1.
|
||||
void Socket::Server::close(){
|
||||
#if DEBUG >= 4
|
||||
fprintf(stderr, "ServerSocket closed.\n");
|
||||
#endif
|
||||
shutdown(sock, SHUT_RDWR);
|
||||
::close(sock);
|
||||
sock = -1;
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace Socket{
|
|||
void close(); ///< Close connection.
|
||||
std::string getHost(); ///< Gets hostname for connection, if available.
|
||||
int getSocket(); ///< Returns internal socket number.
|
||||
std::string getError(); ///< Returns a string describing the last error that occured.
|
||||
friend class Server;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue