Nieuwe flv parser, nieuwe unix sockets support...

This commit is contained in:
Thulinma 2010-11-08 15:28:56 +01:00
parent 206eb006a9
commit 2529d5c0f0
4 changed files with 156 additions and 57 deletions

View file

@ -1,13 +1,34 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
bool socketError = false;
int DDV_OpenUnix(const char adres[], bool nonblock = false){
int s = socket(AF_UNIX, SOCK_STREAM, 0);
sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, adres);
int r = connect(s, (sockaddr*)&adres, sizeof(addr));
if (r == 0){
if (nonblock){
int flags = fcntl(s, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(s, F_SETFL, flags);
}
return s;
}else{
close(s);
return 0;
}
}
int DDV_Listen(int port){
int s = socket(AF_INET, SOCK_STREAM, 0);
@ -36,9 +57,8 @@ int DDV_Accept(int sock){
return accept(sock, 0, 0);
}
bool DDV_write(void * buffer, int width, int count, int sock){
bool DDV_write(void * buffer, int todo, int sock){
int sofar = 0;
int todo = width*count;
while (sofar != todo){
int r = send(sock, (char*)buffer + sofar, todo-sofar, 0);
if (r <= 0){
@ -51,9 +71,8 @@ bool DDV_write(void * buffer, int width, int count, int sock){
return true;
}
bool DDV_read(void * buffer, int width, int count, int sock){
bool DDV_read(void * buffer, int todo, int sock){
int sofar = 0;
int todo = width*count;
while (sofar != todo){
int r = recv(sock, (char*)buffer + sofar, todo-sofar, 0);
if (r <= 0){
@ -65,3 +84,28 @@ bool DDV_read(void * buffer, int width, int count, int sock){
}
return true;
}
bool DDV_read(void * buffer, int width, int count, int sock){return DDV_read(buffer, width*count, sock);}
bool DDV_write(void * buffer, int width, int count, int sock){return DDV_write(buffer, width*count, sock);}
int DDV_iwrite(void * buffer, int todo, int sock){
int r = send(sock, buffer, todo, 0);
if (r < 0){
socketError = true;
printf("Could not write! %s\n", strerror(errno));
}
return r;
}
int DDV_iread(void * buffer, int todo, int sock){
int r = recv(sock, buffer, todo, 0);
if (r < 0){
socketError = true;
printf("Could not write! %s\n", strerror(errno));
}
return r;
}