Rudiments: /home/dmuse/temp/rudiments/include/rudiments/filedescriptor.h Source File

Rudiments

filedescriptor.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information.
3
4 #ifndef RUDIMENTS_FILEDESCRIPTOR_H
5 #define RUDIMENTS_FILEDESCRIPTOR_H
6
7 #include <rudiments/private/filedescriptorincludes.h>
8
9 class listener;
10
13 class RUDIMENTS_DLLSPEC filedescriptor : public input, public output {
14 public:
16 filedescriptor();
17
20 filedescriptor(const filedescriptor &f);
21
24 filedescriptor &operator=(const filedescriptor &f);
25
28 virtual ~filedescriptor();
29
32 virtual bool close();
33
35 int32_t getFileDescriptor() const;
36
39 void setFileDescriptor(int32_t filedesc);
40
50 int32_t duplicate() const;
51
58 bool duplicate(int32_t newfd) const;
59
62 void setSecurityContext(securitycontext *ctx);
63
67 securitycontext *getSecurityContext();
68
71 virtual bool supportsBlockingNonBlockingModes();
72
76 virtual bool useNonBlockingMode() const;
77
81 virtual bool useBlockingMode() const;
82
85 virtual bool isUsingNonBlockingMode() const;
86
90 ssize_t write(uint16_t number);
91
95 ssize_t write(uint32_t number);
96
100 ssize_t write(uint64_t number);
101
105 ssize_t write(int16_t number);
106
110 ssize_t write(int32_t number);
111
115 ssize_t write(int64_t number);
116
120 ssize_t write(float number);
121
125 ssize_t write(double number);
126
130 ssize_t write(unsigned char character);
131
135 ssize_t write(char character);
136
140 ssize_t write(bool value);
141
145 ssize_t write(const unsigned char *string);
146
150 ssize_t write(const char *string);
151
157 ssize_t write(const unsigned char *string, size_t size);
158
164 ssize_t write(const char *string, size_t length);
165
169 ssize_t write(const void *buffer, size_t size);
170
176 ssize_t write(uint16_t number, int32_t sec, int32_t usec);
177
183 ssize_t write(uint32_t number, int32_t sec, int32_t usec);
184
190 ssize_t write(uint64_t number, int32_t sec, int32_t usec);
191
197 ssize_t write(int16_t number, int32_t sec, int32_t usec);
198
204 ssize_t write(int32_t number, int32_t sec, int32_t usec);
205
211 ssize_t write(int64_t number, int32_t sec, int32_t usec);
212
218 ssize_t write(float number, int32_t sec, int32_t usec);
219
225 ssize_t write(double number, int32_t sec, int32_t usec);
226
232 ssize_t write(unsigned char character,
233 int32_t sec, int32_t usec);
234
240 ssize_t write(char character, int32_t sec, int32_t usec);
241
247 ssize_t write(bool value, int32_t sec, int32_t usec);
248
254 ssize_t write(const unsigned char *string,
255 int32_t sec, int32_t usec);
256
262 ssize_t write(const char *string,
263 int32_t sec, int32_t usec);
264
271 ssize_t write(const unsigned char *string, size_t size,
272 int32_t sec, int32_t usec);
273
280 ssize_t write(const char *string, size_t size,
281 int32_t sec, int32_t usec);
282
288 ssize_t write(const void *buffer, size_t size,
289 int32_t sec, int32_t usec);
290
293 size_t printf(const char *format, ...);
294
300 size_t printf(const char *format, va_list *argp);
301
306 void safePrint(unsigned char c);
307
312 void safePrint(const unsigned char *str);
313
318 void safePrint(const unsigned char *str, int32_t length);
319
324 void safePrint(char c);
325
330 void safePrint(const char *str);
331
336 void safePrint(const char *str, int32_t length);
337
340 void printBits(unsigned char value);
341
344 void printBits(uint16_t value);
345
348 void printBits(uint32_t value);
349
352 void printBits(uint64_t value);
353
356 void printBits(char value);
357
360 void printBits(int16_t value);
361
364 void printBits(int32_t value);
365
368 void printBits(int64_t value);
369
372 void printBits(const unsigned char *bits, uint64_t size);
373
378 ssize_t read(uint16_t *buffer);
379
384 ssize_t read(uint32_t *buffer);
385
390 ssize_t read(uint64_t *buffer);
391
395 ssize_t read(int16_t *buffer);
396
400 ssize_t read(int32_t *buffer);
401
405 ssize_t read(int64_t *buffer);
406
411 ssize_t read(float *buffer);
412
417 ssize_t read(double *buffer);
418
423 ssize_t read(unsigned char *buffer);
424
428 ssize_t read(char *buffer);
429
433 ssize_t read(bool *buffer);
434
438 ssize_t read(unsigned char *buffer, size_t size);
439
443 ssize_t read(char *buffer, size_t length);
444
448 ssize_t read(void *buf, size_t size);
449
458 ssize_t read(char **buffer, const char *terminator);
459
471 ssize_t read(char **buffer,
472 const char *terminator, size_t maxbytes);
473
479 ssize_t read(uint16_t *buffer, int32_t sec, int32_t usec);
480
486 ssize_t read(uint32_t *buffer, int32_t sec, int32_t usec);
487
493 ssize_t read(uint64_t *buffer, int32_t sec, int32_t usec);
494
500 ssize_t read(int16_t *buffer, int32_t sec, int32_t usec);
501
507 ssize_t read(int32_t *buffer, int32_t sec, int32_t usec);
508
514 ssize_t read(int64_t *buffer, int32_t sec, int32_t usec);
515
521 ssize_t read(float *buffer, int32_t sec, int32_t usec);
522
528 ssize_t read(double *buffer, int32_t sec, int32_t usec);
529
535 ssize_t read(unsigned char *buffer, int32_t sec, int32_t usec);
536
542 ssize_t read(char *buffer, int32_t sec, int32_t usec);
543
549 ssize_t read(bool *buffer, int32_t sec, int32_t usec);
550
556 ssize_t read(unsigned char *buffer, size_t size,
557 int32_t sec, int32_t usec);
558
564 ssize_t read(char *buffer, size_t size,
565 int32_t sec, int32_t usec);
566
572 ssize_t read(void *buf, size_t size,
573 int32_t sec, int32_t usec);
574
584 ssize_t read(char **buffer, const char *terminator,
585 int32_t sec, int32_t usec);
586
599 ssize_t read(char **buffer,
600 const char *terminator, size_t maxbytes,
601 int32_t sec, int32_t usec);
602
618 ssize_t read(char **buffer,
619 const char *terminator, size_t maxbytes,
620 char escapechar, int32_t sec, int32_t usec);
621
622
642 int32_t waitForNonBlockingRead(int32_t sec, int32_t usec)
643 const;
644
665 int32_t waitForNonBlockingWrite(int32_t sec, int32_t usec)
666 const;
667
668
673 void retryInterruptedReads();
674
680 void dontRetryInterruptedReads();
681
684 bool getRetryInterruptedReads() const;
685
690 void retryInterruptedWrites();
691
697 void dontRetryInterruptedWrites();
698
701 bool getRetryInterruptedWrites() const;
702
708 void retryInterruptedWaits();
709
715 void dontRetryInterruptedWaits();
716
719 bool getRetryInterruptedWaits() const;
720
726 void retryInterruptedFcntl();
727
733 void dontRetryInterruptedFcntl();
734
737 bool getRetryInterruptedFcntl() const;
738
744 void retryInterruptedIoctl();
745
751 void dontRetryInterruptedIoctl();
752
755 bool getRetryInterruptedIoctl() const;
756
757
768 void allowShortReads();
769
775 void dontAllowShortReads();
776
788 void allowShortWrites();
789
795 void dontAllowShortWrites();
796
797
801 virtual bool passFileDescriptor(int32_t fd);
802
806 virtual bool receiveFileDescriptor(int32_t *fd);
807
808
812 virtual bool passSocket(int32_t sock);
813
817 virtual bool receiveSocket(int32_t *sock);
818
819
823 void translateByteOrder();
824
828 void dontTranslateByteOrder();
829
832 virtual int32_t fCntl(int32_t command, long arg) const;
833
836 virtual int32_t ioCtl(int32_t command, void *arg) const;
837
846 bool useNaglesAlgorithm();
847
852 bool dontUseNaglesAlgorithm();
853
857 bool setSocketWriteBufferSize(int32_t size);
858
863 bool getSocketWriteBufferSize(int32_t *size);
864
868 bool setSocketReadBufferSize(int32_t size);
869
874 bool getSocketReadBufferSize(int32_t *size);
875
879 bool disableIPv4();
880
885 bool enableIPv4();
886
891 const char *getType() const;
892
899 char *getPeerAddress() const;
900
901
923 bool setWriteBufferSize(ssize_t size) const;
924
951 bool flushWriteBuffer(int32_t sec, int32_t usec);
952
953
973 bool setReadBufferSize(ssize_t size) const;
974
980 bool closeOnExec();
981
988 bool dontCloseOnExec();
989
996 bool getCloseOnExec();
997
1000 static bool createPipe(filedescriptor *readfd,
1001 filedescriptor *writefd);
1002
1005 static uint16_t hostToNet(uint16_t value);
1006
1009 static uint32_t hostToNet(uint32_t value);
1010
1013 static uint64_t hostToNet(uint64_t value);
1014
1017 static uint16_t netToHost(uint16_t value);
1018
1021 static uint32_t netToHost(uint32_t value);
1022
1025 static uint64_t netToHost(uint64_t value);
1026
1029 static uint16_t hostToLittleEndian(uint16_t value);
1030
1033 static uint32_t hostToLittleEndian(uint32_t value);
1034
1037 static uint64_t hostToLittleEndian(uint64_t value);
1038
1041 static uint16_t littleEndianToHost(uint16_t value);
1042
1045 static uint32_t littleEndianToHost(uint32_t value);
1046
1049 static uint64_t littleEndianToHost(uint64_t value);
1050
1051 #include <rudiments/private/filedescriptor.h>
1052 };
1053
1054 #endif
character
Definition: character.h:11
filedescriptor
Definition: filedescriptor.h:13
filedescriptor::fCntl
virtual int32_t fCntl(int32_t command, long arg) const
filedescriptor::hostToNet
static uint16_t hostToNet(uint16_t value)
filedescriptor::filedescriptor
filedescriptor()
filedescriptor::write
ssize_t write(char character)
filedescriptor::read
ssize_t read(unsigned char *buffer, size_t size, int32_t sec, int32_t usec)
filedescriptor::getRetryInterruptedReads
bool getRetryInterruptedReads() const
filedescriptor::write
ssize_t write(const unsigned char *string, int32_t sec, int32_t usec)
filedescriptor::netToHost
static uint32_t netToHost(uint32_t value)
filedescriptor::receiveSocket
virtual bool receiveSocket(int32_t *sock)
filedescriptor::read
ssize_t read(void *buf, size_t size, int32_t sec, int32_t usec)
filedescriptor::retryInterruptedIoctl
void retryInterruptedIoctl()
filedescriptor::write
ssize_t write(int64_t number)
filedescriptor::read
ssize_t read(int16_t *buffer)
filedescriptor::printBits
void printBits(unsigned char value)
filedescriptor::write
ssize_t write(uint16_t number)
filedescriptor::hostToLittleEndian
static uint16_t hostToLittleEndian(uint16_t value)
filedescriptor::littleEndianToHost
static uint16_t littleEndianToHost(uint16_t value)
filedescriptor::littleEndianToHost
static uint32_t littleEndianToHost(uint32_t value)
filedescriptor::read
ssize_t read(double *buffer)
filedescriptor::write
ssize_t write(const char *string)
filedescriptor::write
ssize_t write(uint16_t number, int32_t sec, int32_t usec)
filedescriptor::passFileDescriptor
virtual bool passFileDescriptor(int32_t fd)
filedescriptor::hostToNet
static uint64_t hostToNet(uint64_t value)
filedescriptor::ioCtl
virtual int32_t ioCtl(int32_t command, void *arg) const
filedescriptor::write
ssize_t write(uint64_t number, int32_t sec, int32_t usec)
filedescriptor::getRetryInterruptedWaits
bool getRetryInterruptedWaits() const
filedescriptor::printBits
void printBits(uint64_t value)
filedescriptor::write
ssize_t write(const unsigned char *string)
filedescriptor::getCloseOnExec
bool getCloseOnExec()
filedescriptor::write
ssize_t write(double number)
filedescriptor::write
ssize_t write(uint32_t number, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(float *buffer, int32_t sec, int32_t usec)
filedescriptor::safePrint
void safePrint(unsigned char c)
filedescriptor::dontRetryInterruptedFcntl
void dontRetryInterruptedFcntl()
filedescriptor::operator=
filedescriptor & operator=(const filedescriptor &f)
filedescriptor::read
ssize_t read(char *buffer, int32_t sec, int32_t usec)
filedescriptor::waitForNonBlockingRead
int32_t waitForNonBlockingRead(int32_t sec, int32_t usec) const
filedescriptor::write
ssize_t write(int32_t number)
filedescriptor::read
ssize_t read(int16_t *buffer, int32_t sec, int32_t usec)
filedescriptor::write
ssize_t write(const unsigned char *string, size_t size, int32_t sec, int32_t usec)
filedescriptor::write
ssize_t write(uint32_t number)
filedescriptor::dontUseNaglesAlgorithm
bool dontUseNaglesAlgorithm()
filedescriptor::setReadBufferSize
bool setReadBufferSize(ssize_t size) const
filedescriptor::hostToLittleEndian
static uint32_t hostToLittleEndian(uint32_t value)
filedescriptor::useNonBlockingMode
virtual bool useNonBlockingMode() const
filedescriptor::dontAllowShortReads
void dontAllowShortReads()
filedescriptor::useBlockingMode
virtual bool useBlockingMode() const
filedescriptor::write
ssize_t write(unsigned char character)
filedescriptor::read
ssize_t read(unsigned char *buffer, int32_t sec, int32_t usec)
filedescriptor::setSecurityContext
void setSecurityContext(securitycontext *ctx)
filedescriptor::littleEndianToHost
static uint64_t littleEndianToHost(uint64_t value)
filedescriptor::read
ssize_t read(char **buffer, const char *terminator, int32_t sec, int32_t usec)
filedescriptor::translateByteOrder
void translateByteOrder()
filedescriptor::dontRetryInterruptedIoctl
void dontRetryInterruptedIoctl()
filedescriptor::read
ssize_t read(char **buffer, const char *terminator, size_t maxbytes)
filedescriptor::write
ssize_t write(const char *string, int32_t sec, int32_t usec)
filedescriptor::dontAllowShortWrites
void dontAllowShortWrites()
filedescriptor::dontTranslateByteOrder
void dontTranslateByteOrder()
filedescriptor::printBits
void printBits(char value)
filedescriptor::read
ssize_t read(char *buffer)
filedescriptor::write
ssize_t write(const unsigned char *string, size_t size)
filedescriptor::hostToLittleEndian
static uint64_t hostToLittleEndian(uint64_t value)
filedescriptor::setFileDescriptor
void setFileDescriptor(int32_t filedesc)
filedescriptor::read
ssize_t read(uint64_t *buffer)
filedescriptor::read
ssize_t read(int32_t *buffer)
filedescriptor::read
ssize_t read(char **buffer, const char *terminator, size_t maxbytes, char escapechar, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(bool *buffer, int32_t sec, int32_t usec)
filedescriptor::close
virtual bool close()
filedescriptor::getRetryInterruptedWrites
bool getRetryInterruptedWrites() const
filedescriptor::printBits
void printBits(int16_t value)
filedescriptor::read
ssize_t read(uint32_t *buffer)
filedescriptor::netToHost
static uint16_t netToHost(uint16_t value)
filedescriptor::useNaglesAlgorithm
bool useNaglesAlgorithm()
filedescriptor::read
ssize_t read(int64_t *buffer, int32_t sec, int32_t usec)
filedescriptor::write
ssize_t write(const void *buffer, size_t size, int32_t sec, int32_t usec)
filedescriptor::setSocketWriteBufferSize
bool setSocketWriteBufferSize(int32_t size)
filedescriptor::safePrint
void safePrint(const unsigned char *str, int32_t length)
filedescriptor::read
ssize_t read(unsigned char *buffer, size_t size)
filedescriptor::dontCloseOnExec
bool dontCloseOnExec()
filedescriptor::getType
const char * getType() const
filedescriptor::write
ssize_t write(char character, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(char *buffer, size_t length)
filedescriptor::dontRetryInterruptedReads
void dontRetryInterruptedReads()
filedescriptor::getPeerAddress
char * getPeerAddress() const
filedescriptor::write
ssize_t write(double number, int32_t sec, int32_t usec)
filedescriptor::allowShortReads
void allowShortReads()
filedescriptor::printBits
void printBits(int32_t value)
filedescriptor::setWriteBufferSize
bool setWriteBufferSize(ssize_t size) const
filedescriptor::retryInterruptedReads
void retryInterruptedReads()
filedescriptor::dontRetryInterruptedWaits
void dontRetryInterruptedWaits()
filedescriptor::read
ssize_t read(void *buf, size_t size)
filedescriptor::read
ssize_t read(char *buffer, size_t size, int32_t sec, int32_t usec)
filedescriptor::filedescriptor
filedescriptor(const filedescriptor &f)
filedescriptor::read
ssize_t read(float *buffer)
filedescriptor::read
ssize_t read(char **buffer, const char *terminator, size_t maxbytes, int32_t sec, int32_t usec)
filedescriptor::write
ssize_t write(bool value, int32_t sec, int32_t usec)
filedescriptor::write
ssize_t write(int32_t number, int32_t sec, int32_t usec)
filedescriptor::createPipe
static bool createPipe(filedescriptor *readfd, filedescriptor *writefd)
filedescriptor::printBits
void printBits(const unsigned char *bits, uint64_t size)
filedescriptor::duplicate
int32_t duplicate() const
filedescriptor::flushWriteBuffer
bool flushWriteBuffer(int32_t sec, int32_t usec)
filedescriptor::setSocketReadBufferSize
bool setSocketReadBufferSize(int32_t size)
filedescriptor::getRetryInterruptedIoctl
bool getRetryInterruptedIoctl() const
filedescriptor::getFileDescriptor
int32_t getFileDescriptor() const
filedescriptor::closeOnExec
bool closeOnExec()
filedescriptor::safePrint
void safePrint(const unsigned char *str)
filedescriptor::read
ssize_t read(uint64_t *buffer, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(uint16_t *buffer)
filedescriptor::read
ssize_t read(int64_t *buffer)
filedescriptor::write
ssize_t write(int16_t number)
filedescriptor::getSocketReadBufferSize
bool getSocketReadBufferSize(int32_t *size)
filedescriptor::write
ssize_t write(float number)
filedescriptor::hostToNet
static uint32_t hostToNet(uint32_t value)
filedescriptor::read
ssize_t read(bool *buffer)
filedescriptor::write
ssize_t write(bool value)
filedescriptor::read
ssize_t read(unsigned char *buffer)
filedescriptor::passSocket
virtual bool passSocket(int32_t sock)
filedescriptor::enableIPv4
bool enableIPv4()
filedescriptor::supportsBlockingNonBlockingModes
virtual bool supportsBlockingNonBlockingModes()
filedescriptor::write
ssize_t write(int16_t number, int32_t sec, int32_t usec)
filedescriptor::printf
size_t printf(const char *format, va_list *argp)
filedescriptor::read
ssize_t read(int32_t *buffer, int32_t sec, int32_t usec)
filedescriptor::allowShortWrites
void allowShortWrites()
filedescriptor::netToHost
static uint64_t netToHost(uint64_t value)
filedescriptor::write
ssize_t write(const void *buffer, size_t size)
filedescriptor::write
ssize_t write(int64_t number, int32_t sec, int32_t usec)
filedescriptor::printBits
void printBits(uint32_t value)
filedescriptor::write
ssize_t write(uint64_t number)
filedescriptor::retryInterruptedWrites
void retryInterruptedWrites()
filedescriptor::dontRetryInterruptedWrites
void dontRetryInterruptedWrites()
filedescriptor::isUsingNonBlockingMode
virtual bool isUsingNonBlockingMode() const
filedescriptor::retryInterruptedFcntl
void retryInterruptedFcntl()
filedescriptor::getRetryInterruptedFcntl
bool getRetryInterruptedFcntl() const
filedescriptor::printBits
void printBits(uint16_t value)
filedescriptor::safePrint
void safePrint(char c)
filedescriptor::duplicate
bool duplicate(int32_t newfd) const
filedescriptor::waitForNonBlockingWrite
int32_t waitForNonBlockingWrite(int32_t sec, int32_t usec) const
filedescriptor::getSecurityContext
securitycontext * getSecurityContext()
filedescriptor::write
ssize_t write(unsigned char character, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(char **buffer, const char *terminator)
filedescriptor::safePrint
void safePrint(const char *str)
filedescriptor::read
ssize_t read(double *buffer, int32_t sec, int32_t usec)
filedescriptor::printBits
void printBits(int64_t value)
filedescriptor::~filedescriptor
virtual ~filedescriptor()
filedescriptor::retryInterruptedWaits
void retryInterruptedWaits()
filedescriptor::write
ssize_t write(const char *string, size_t length)
filedescriptor::write
ssize_t write(const char *string, size_t size, int32_t sec, int32_t usec)
filedescriptor::printf
size_t printf(const char *format,...)
filedescriptor::read
ssize_t read(uint32_t *buffer, int32_t sec, int32_t usec)
filedescriptor::getSocketWriteBufferSize
bool getSocketWriteBufferSize(int32_t *size)
filedescriptor::disableIPv4
bool disableIPv4()
filedescriptor::receiveFileDescriptor
virtual bool receiveFileDescriptor(int32_t *fd)
filedescriptor::safePrint
void safePrint(const char *str, int32_t length)
filedescriptor::write
ssize_t write(float number, int32_t sec, int32_t usec)
filedescriptor::read
ssize_t read(uint16_t *buffer, int32_t sec, int32_t usec)
input
Definition: input.h:9
listener
Definition: listener.h:14
output
Definition: output.h:9
securitycontext
Definition: security.h:16