Merge branch 'master' of projectlivestream.com:pls
This commit is contained in:
commit
3790443e69
2 changed files with 44 additions and 17 deletions
|
@ -33,7 +33,6 @@ int DDV_OpenUnix(std::string adres, bool nonblock = false){
|
|||
|
||||
int DDV_Listen(int port){
|
||||
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
int on = 1;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||
struct sockaddr_in addr;
|
||||
|
@ -46,12 +45,40 @@ int DDV_Listen(int port){
|
|||
if (ret == 0){
|
||||
return s;
|
||||
}else{
|
||||
printf("Listen failed! Error: %s\n", strerror(errno));
|
||||
fprintf(stderr, "Listen failed! Error: %s\n", strerror(errno));
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
printf("Binding failed! Error: %s\n", strerror(errno));
|
||||
fprintf(stderr, "Binding failed! Error: %s\n", strerror(errno));
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int DDV_UnixListen(std::string adres, bool nonblock = false){
|
||||
unlink(adres.c_str());
|
||||
int s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (nonblock){
|
||||
int flags = fcntl(s, F_GETFL, 0);
|
||||
flags |= O_NONBLOCK;
|
||||
fcntl(s, F_SETFL, flags);
|
||||
}
|
||||
sockaddr_un addr;
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, adres.c_str(), adres.size()+1);
|
||||
int ret = bind(s, (sockaddr*)&addr, sizeof(addr));
|
||||
if (ret == 0){
|
||||
ret = listen(s, 100);//start listening, backlog of 100 allowed
|
||||
if (ret == 0){
|
||||
return s;
|
||||
}else{
|
||||
fprintf(stderr, "Listen failed! Error: %s\n", strerror(errno));
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
fprintf(stderr, "Binding failed! Error: %s\n", strerror(errno));
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,7 +86,7 @@ int DDV_Listen(int port){
|
|||
|
||||
int DDV_Accept(int sock, bool nonblock = false){
|
||||
int r = accept(sock, 0, 0);
|
||||
if ((r > 0) && nonblock){
|
||||
if ((r >= 0) && nonblock){
|
||||
int flags = fcntl(r, F_GETFL, 0);
|
||||
flags |= O_NONBLOCK;
|
||||
fcntl(r, F_SETFL, flags);
|
||||
|
@ -77,7 +104,7 @@ bool DDV_write(void * buffer, int todo, int sock){
|
|||
case EWOULDBLOCK: socketBlocking = true; break;
|
||||
default:
|
||||
socketError = true;
|
||||
printf("Could not write! %s\n", strerror(errno));
|
||||
fprintf(stderr, "Could not write! %s\n", strerror(errno));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
@ -87,14 +114,14 @@ bool DDV_write(void * buffer, int todo, int sock){
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DDV_ready(int sock){
|
||||
signed int DDV_ready(int sock){
|
||||
char tmp;
|
||||
int preflags = fcntl(sock, F_GETFL, 0);
|
||||
int postflags = preflags | O_NONBLOCK;
|
||||
fcntl(sock, F_SETFL, postflags);
|
||||
int r = recv(sock, &tmp, 1, MSG_PEEK);
|
||||
fcntl(sock, F_SETFL, preflags);
|
||||
return (r == 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool DDV_read(void * buffer, int todo, int sock){
|
||||
|
@ -107,7 +134,7 @@ bool DDV_read(void * buffer, int todo, int sock){
|
|||
case EWOULDBLOCK: socketBlocking = true; break;
|
||||
default:
|
||||
socketError = true;
|
||||
printf("Could not read! %s\n", strerror(errno));
|
||||
fprintf(stderr, "Could not read! %s\n", strerror(errno));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
@ -126,11 +153,11 @@ int DDV_iwrite(void * buffer, int todo, int sock){
|
|||
int r = send(sock, buffer, todo, 0);
|
||||
if (r < 0){
|
||||
switch (errno){
|
||||
case EWOULDBLOCK: break;
|
||||
case EWOULDBLOCK: return 0; break;
|
||||
default:
|
||||
socketError = true;
|
||||
printf("Could not write! %s\n", strerror(errno));
|
||||
return false;
|
||||
fprintf(stderr, "Could not write! %s\n", strerror(errno));
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -144,8 +171,8 @@ int DDV_iread(void * buffer, int todo, int sock){
|
|||
case EWOULDBLOCK: break;
|
||||
default:
|
||||
socketError = true;
|
||||
printf("Could not read! %s\n", strerror(errno));
|
||||
return false;
|
||||
fprintf(stderr, "Could not read! %s\n", strerror(errno));
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ bool FLV_GetPacket(FLV_Pack *& p, int sock){
|
|||
if (FLV_Checkheader(p->data)){
|
||||
sofar = 0;
|
||||
memcpy(FLVHeader, p->data, 13);
|
||||
//fwrite(p->data, 13, 1, stdout);//output raw stream
|
||||
}else{
|
||||
All_Hell_Broke_Loose = true;
|
||||
fprintf(stderr, "Invalid FLV header. All Hell Broke Loose!\n");
|
||||
|
@ -94,12 +95,11 @@ bool FLV_GetPacket(FLV_Pack *& p, int sock){
|
|||
testlen += (p->data[p->len-2] << 8);
|
||||
testlen += (p->data[p->len-3] << 16);
|
||||
testlen += (p->data[p->len-4] << 24);
|
||||
if (p->len == testlen){
|
||||
fprintf(stderr, "Correct length tag...\n");
|
||||
}else{
|
||||
//fwrite(p->data, p->len, 1, stdout);//output raw stream
|
||||
if (p->len != testlen){
|
||||
fprintf(stderr, "Len: %i, testlen: %i\n", p->len, testlen);
|
||||
All_Hell_Broke_Loose = true;
|
||||
fprintf(stderr, "ReadUntil fail: > 500kb tag? All Hell Broke Loose!\n", strerror(errno));
|
||||
fprintf(stderr, "ReadUntil fail: Wrong size tag? All Hell Broke Loose!\n");
|
||||
return false;
|
||||
}
|
||||
done = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue