8 #include "networktables2/stream/FDIOStream.h"
9 #include "networktables2/util/IOException.h"
10 #include "networktables2/util/EOFException.h"
15 #include <selectLib.h>
20 FDIOStream::FDIOStream(
int _fd){
26 FDIOStream::~FDIOStream(){
30 int FDIOStream::read(
void* ptr,
int numbytes){
33 char* bufferPointer = (
char*)ptr;
36 struct timeval timeout;
39 while (totalRead < numbytes) {
44 int select_result = select(FD_SETSIZE, &fdSet, NULL, NULL, &timeout);
45 if ( select_result < 0)
46 throw IOException(
"Select returned an error on read");
49 if (FD_ISSET(fd, &fdSet)) {
50 numRead = ::read(fd, bufferPointer, numbytes-totalRead);
55 else if (numRead < 0) {
56 perror(
"read error: ");
60 bufferPointer += numRead;
66 int FDIOStream::write(
const void* ptr,
int numbytes){
67 int numWrote = ::write(fd, (
char*)ptr, numbytes);
69 if(numWrote==numbytes)
71 perror(
"write error: ");
73 throw IOException(
"Could not write all bytes to fd stream");
76 void FDIOStream::flush(){
80 void FDIOStream::close(){