try for accept

This commit is contained in:
Erik Frojdh
2019-05-15 12:17:32 +02:00
parent c632badb55
commit 40c2d9f760
6 changed files with 83 additions and 51 deletions

View File

@ -9,6 +9,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
namespace sls {
@ -43,12 +44,25 @@ size_t DataSocket::receiveData(void *buffer, size_t size) {
size_t dataRead = 0;
while (dataRead < size) {
dataRead +=
read(getSocketId(), reinterpret_cast<char *>(buffer) + dataRead,
::read(getSocketId(), reinterpret_cast<char *>(buffer) + dataRead,
size - dataRead);
}
return dataRead;
}
size_t DataSocket::read(void *buffer, size_t size){
return ::read(getSocketId(), reinterpret_cast<char *>(buffer), size);
}
int DataSocket::setReceiveTimeout(int us) {
timeval t{};
t.tv_sec = 0;
t.tv_usec = us;
return ::setsockopt(getSocketId(), SOL_SOCKET, SO_RCVTIMEO, &t,
sizeof(struct timeval));
}
size_t DataSocket::sendData(const void *buffer, size_t size) {
size_t dataSent = 0;
while (dataSent < size) {