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:
Thulinma 2011-08-12 02:03:07 +02:00
parent 9af2bc0d93
commit 07aff5ad16
4 changed files with 44 additions and 16 deletions

View file

@ -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;
@ -79,7 +79,7 @@ namespace Buffer{
void Send(buffer ** ringbuf, int buffers){
/// \todo For MP3: gotproperaudio - if false, only send if first byte is 0xFF and set to true
if (!S.connected()){return;}//cancel if not connected
//still waiting for next buffer? check it
if (MyBuffer_num < 0){
MyBuffer_num = ringbuf[MyBuffer]->number;
@ -90,13 +90,13 @@ namespace Buffer{
lastpointer = ringbuf[MyBuffer]->FLV.data;
}
}
//do check for buffer resizes
if (lastpointer != ringbuf[MyBuffer]->FLV.data){
Disconnect("Buffer resize at wrong time... had to disconnect");
return;
}
//try to complete a send
if (doSend()){
//switch to next buffer
@ -156,13 +156,13 @@ namespace Buffer{
int lastproper = 0;//last properly finished buffer number
unsigned int loopcount = 0;
Socket::Connection incoming;
unsigned char packtype;
bool gotVideoInfo = false;
bool gotAudioInfo = false;
int infile = fileno(stdin);//get file number for stdin
//add stdin to an epoll
int poller = epoll_create(1);
struct epoll_event ev;
@ -170,8 +170,8 @@ namespace Buffer{
ev.data.fd = infile;
epoll_ctl(poller, EPOLL_CTL_ADD, infile, &ev);
struct epoll_event events[1];
while(!feof(stdin) && !FLV::Parse_Error){
//invalidate the current buffer
ringbuf[current_buffer]->number = -1;

Binary file not shown.

View file

@ -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
@ -285,7 +304,7 @@ std::string Socket::Connection::getHost(){
Socket::Server::Server(){
sock = -1;
}//Socket::Server base Constructor
/// Create a new TCP Server. The socket is immediately bound and set to listen.
/// A maximum of 100 connections will be accepted between accept() calls.
/// Any further connections coming in will be dropped.
@ -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;

View file

@ -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;
};
@ -61,5 +62,5 @@ namespace Socket{
void close(); ///< Close connection.
int getSocket(); ///< Returns internal socket number.
};
};