Rudiments
|
00001 // Copyright (c) 2002 David Muse 00002 // See the COPYING file for more information. 00003 00004 #ifndef RUDIMENTS_FILEDESCRIPTOR_H 00005 #define RUDIMENTS_FILEDESCRIPTOR_H 00006 00007 #include <rudiments/private/filedescriptorincludes.h> 00008 00009 #ifdef RUDIMENTS_NAMESPACE 00010 namespace rudiments { 00011 #endif 00012 00013 class listener; 00014 class filedescriptorprivate; 00015 00018 class RUDIMENTS_DLLSPEC filedescriptor { 00019 public: 00021 filedescriptor(); 00022 00025 filedescriptor(const filedescriptor &f); 00026 00029 filedescriptor &operator=(const filedescriptor &f); 00030 00033 virtual ~filedescriptor(); 00034 00037 virtual bool close(); 00038 00040 int32_t getFileDescriptor() const; 00041 00044 void setFileDescriptor(int32_t filedesc); 00045 00055 int32_t duplicate() const; 00056 00063 bool duplicate(int32_t newfd) const; 00064 00065 #ifdef RUDIMENTS_HAS_SSL 00066 00070 void setSSLContext(SSL_CTX *ctx); 00071 00075 SSL_CTX *getSSLContext(); 00076 00086 bool initializeSSL(); 00087 00092 SSL *getSSL() const; 00093 00098 void deInitializeSSL(); 00099 00106 int32_t getSSLResult() const; 00107 #endif 00108 00111 virtual bool supportsBlockingNonBlockingModes(); 00112 00116 virtual bool useNonBlockingMode() const; 00117 00121 virtual bool useBlockingMode() const; 00122 00125 virtual bool isUsingNonBlockingMode() const; 00126 00130 ssize_t write(uint16_t number) const; 00131 00135 ssize_t write(uint32_t number) const; 00136 00140 ssize_t write(uint64_t number) const; 00141 00145 ssize_t write(int16_t number) const; 00146 00150 ssize_t write(int32_t number) const; 00151 00155 ssize_t write(int64_t number) const; 00156 00160 ssize_t write(float number) const; 00161 00165 ssize_t write(double number) const; 00166 00170 ssize_t write(unsigned char character) const; 00171 00175 ssize_t write(char character) const; 00176 00180 ssize_t write(bool value) const; 00181 00185 ssize_t write(const unsigned char *string) const; 00186 00190 ssize_t write(const char *string) const; 00191 00197 ssize_t write(const unsigned char *string, size_t size) const; 00198 00204 ssize_t write(const char *string, size_t size) const; 00205 00209 ssize_t write(const void *buffer, size_t size) const; 00210 00216 ssize_t write(uint16_t number, long sec, long usec) const; 00217 00223 ssize_t write(uint32_t number, long sec, long usec) const; 00224 00230 ssize_t write(uint64_t number, long sec, long usec) const; 00231 00237 ssize_t write(int16_t number, long sec, long usec) const; 00238 00244 ssize_t write(int32_t number, long sec, long usec) const; 00245 00251 ssize_t write(int64_t number, long sec, long usec) const; 00252 00258 ssize_t write(float number, long sec, long usec) const; 00259 00265 ssize_t write(double number, long sec, long usec) const; 00266 00272 ssize_t write(unsigned char character, 00273 long sec, long usec) const; 00274 00280 ssize_t write(char character, long sec, long usec) const; 00281 00287 ssize_t write(bool value, long sec, long usec) const; 00288 00294 ssize_t write(const unsigned char *string, 00295 long sec, long usec) const; 00296 00302 ssize_t write(const char *string, 00303 long sec, long usec) const; 00304 00311 ssize_t write(const unsigned char *string, size_t size, 00312 long sec, long usec) const; 00313 00320 ssize_t write(const char *string, size_t size, 00321 long sec, long usec) const; 00322 00328 ssize_t write(const void *buffer, size_t size, 00329 long sec, long usec) const; 00330 00335 ssize_t read(uint16_t *buffer) const; 00336 00341 ssize_t read(uint32_t *buffer) const; 00342 00347 ssize_t read(uint64_t *buffer) const; 00348 00352 ssize_t read(int16_t *buffer) const; 00353 00357 ssize_t read(int32_t *buffer) const; 00358 00362 ssize_t read(int64_t *buffer) const; 00363 00368 ssize_t read(float *buffer) const; 00369 00374 ssize_t read(double *buffer) const; 00375 00380 ssize_t read(unsigned char *buffer) const; 00381 00385 ssize_t read(char *buffer) const; 00386 00390 ssize_t read(bool *buffer) const; 00391 00395 ssize_t read(unsigned char *buffer, size_t size) const; 00396 00400 ssize_t read(char *buffer, size_t size) const; 00401 00405 ssize_t read(void *buf, size_t size) const; 00406 00415 ssize_t read(char **buffer, const char *terminator) const; 00416 00422 ssize_t read(uint16_t *buffer, long sec, long usec) const; 00423 00429 ssize_t read(uint32_t *buffer, long sec, long usec) const; 00430 00436 ssize_t read(uint64_t *buffer, long sec, long usec) const; 00437 00443 ssize_t read(int16_t *buffer, long sec, long usec) const; 00444 00450 ssize_t read(int32_t *buffer, long sec, long usec) const; 00451 00457 ssize_t read(int64_t *buffer, long sec, long usec) const; 00458 00464 ssize_t read(float *buffer, long sec, long usec) const; 00465 00471 ssize_t read(double *buffer, long sec, long usec) const; 00472 00478 ssize_t read(unsigned char *buffer, 00479 long sec, long usec) const; 00480 00486 ssize_t read(char *buffer, long sec, long usec) const; 00487 00493 ssize_t read(bool *buffer, long sec, long usec) const; 00494 00500 ssize_t read(unsigned char *buffer, size_t size, 00501 long sec, long usec) const; 00502 00508 ssize_t read(char *buffer, size_t size, 00509 long sec, long usec) const; 00510 00516 ssize_t read(void *buf, size_t size, 00517 long sec, long usec) const; 00518 00528 ssize_t read(char **buffer, const char *terminator, 00529 long sec, long usec) const; 00530 00531 00555 int32_t waitForNonBlockingRead(long sec, long usec) const; 00556 00581 int32_t waitForNonBlockingWrite(long sec, long usec) const; 00582 00583 00588 void retryInterruptedReads(); 00589 00595 void dontRetryInterruptedReads(); 00596 00599 bool getRetryInterruptedReads() const; 00600 00605 void retryInterruptedWrites(); 00606 00612 void dontRetryInterruptedWrites(); 00613 00616 bool getRetryInterruptedWrites() const; 00617 00623 void retryInterruptedWaits(); 00624 00630 void dontRetryInterruptedWaits(); 00631 00634 bool getRetryInterruptedWaits() const; 00635 00641 void retryInterruptedFcntl(); 00642 00648 void dontRetryInterruptedFcntl(); 00649 00652 bool getRetryInterruptedFcntl() const; 00653 00659 void retryInterruptedIoctl(); 00660 00666 void dontRetryInterruptedIoctl(); 00667 00670 bool getRetryInterruptedIoctl() const; 00671 00672 00683 void allowShortReads(); 00684 00690 void dontAllowShortReads(); 00691 00703 void allowShortWrites(); 00704 00710 void dontAllowShortWrites(); 00711 00721 void useListener(listener *lstnr); 00722 00729 void dontUseListener(); 00730 00733 listener *getListener(); 00734 00738 void useListenerInsideReads(); 00739 00743 void dontUseListenerInsideReads(); 00744 00748 void useListenerInsideWrites(); 00749 00753 void dontUseListenerInsideWrites(); 00754 00755 00759 virtual bool passFileDescriptor(int32_t fd) const; 00760 00764 virtual bool receiveFileDescriptor(int32_t *fd) const; 00765 00769 void translateByteOrder(); 00770 00774 void dontTranslateByteOrder(); 00775 00778 virtual int32_t fCntl(int32_t command, long arg) const; 00779 00782 virtual int32_t ioCtl(int32_t command, void *arg) const; 00783 00792 bool useNaglesAlgorithm(); 00793 00798 bool dontUseNaglesAlgorithm(); 00799 00804 bool setTcpWriteBufferSize(int32_t size); 00805 00810 bool getTcpWriteBufferSize(int32_t *size); 00811 00816 bool setTcpReadBufferSize(int32_t size); 00817 00822 bool getTcpReadBufferSize(int32_t *size); 00823 00827 bool disableIPv4(); 00828 00833 bool enableIPv4(); 00834 00839 const char *getType() const; 00840 00847 char *getPeerAddress() const; 00848 00849 00871 bool setWriteBufferSize(ssize_t size) const; 00872 00899 bool flushWriteBuffer(long sec, long usec) const; 00900 00901 00921 bool setReadBufferSize(ssize_t size) const; 00922 00928 bool closeOnExec(); 00929 00936 bool dontCloseOnExec(); 00937 00944 bool getCloseOnExec(); 00945 00948 static uint16_t hostToNet(uint16_t value); 00949 00952 static uint32_t hostToNet(uint32_t value); 00953 00956 static uint64_t hostToNet(uint64_t value); 00957 00960 static uint16_t netToHost(uint16_t value); 00961 00964 static uint32_t netToHost(uint32_t value); 00965 00968 static uint64_t netToHost(uint64_t value); 00969 00970 #include <rudiments/private/filedescriptor.h> 00971 }; 00972 00973 #ifdef RUDIMENTS_NAMESPACE 00974 } 00975 #endif 00976 00977 #endif