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 00112 virtual bool useNonBlockingMode() const; 00113 00117 virtual bool useBlockingMode() const; 00118 00121 bool isUsingNonBlockingMode() const; 00122 00126 ssize_t write(uint16_t number) const; 00127 00131 ssize_t write(uint32_t number) const; 00132 00136 ssize_t write(uint64_t number) const; 00137 00141 ssize_t write(int16_t number) const; 00142 00146 ssize_t write(int32_t number) const; 00147 00151 ssize_t write(int64_t number) const; 00152 00156 ssize_t write(float number) const; 00157 00161 ssize_t write(double number) const; 00162 00166 ssize_t write(unsigned char character) const; 00167 00171 ssize_t write(char character) const; 00172 00176 ssize_t write(bool value) const; 00177 00181 ssize_t write(const unsigned char *string) const; 00182 00186 ssize_t write(const char *string) const; 00187 00193 ssize_t write(const unsigned char *string, size_t size) const; 00194 00200 ssize_t write(const char *string, size_t size) const; 00201 00205 ssize_t write(const void *buffer, size_t size) const; 00206 00212 ssize_t write(uint16_t number, long sec, long usec) const; 00213 00219 ssize_t write(uint32_t number, long sec, long usec) const; 00220 00226 ssize_t write(uint64_t number, long sec, long usec) const; 00227 00233 ssize_t write(int16_t number, long sec, long usec) const; 00234 00240 ssize_t write(int32_t number, long sec, long usec) const; 00241 00247 ssize_t write(int64_t number, long sec, long usec) const; 00248 00254 ssize_t write(float number, long sec, long usec) const; 00255 00261 ssize_t write(double number, long sec, long usec) const; 00262 00268 ssize_t write(unsigned char character, 00269 long sec, long usec) const; 00270 00276 ssize_t write(char character, long sec, long usec) const; 00277 00283 ssize_t write(bool value, long sec, long usec) const; 00284 00290 ssize_t write(const unsigned char *string, 00291 long sec, long usec) const; 00292 00298 ssize_t write(const char *string, 00299 long sec, long usec) const; 00300 00307 ssize_t write(const unsigned char *string, size_t size, 00308 long sec, long usec) const; 00309 00316 ssize_t write(const char *string, size_t size, 00317 long sec, long usec) const; 00318 00324 ssize_t write(const void *buffer, size_t size, 00325 long sec, long usec) const; 00326 00331 ssize_t read(uint16_t *buffer) const; 00332 00337 ssize_t read(uint32_t *buffer) const; 00338 00343 ssize_t read(uint64_t *buffer) const; 00344 00348 ssize_t read(int16_t *buffer) const; 00349 00353 ssize_t read(int32_t *buffer) const; 00354 00358 ssize_t read(int64_t *buffer) const; 00359 00364 ssize_t read(float *buffer) const; 00365 00370 ssize_t read(double *buffer) const; 00371 00376 ssize_t read(unsigned char *buffer) const; 00377 00381 ssize_t read(char *buffer) const; 00382 00386 ssize_t read(bool *buffer) const; 00387 00391 ssize_t read(unsigned char *buffer, size_t size) const; 00392 00396 ssize_t read(char *buffer, size_t size) const; 00397 00401 ssize_t read(void *buf, size_t size) const; 00402 00411 ssize_t read(char **buffer, const char *terminator) const; 00412 00418 ssize_t read(uint16_t *buffer, long sec, long usec) const; 00419 00425 ssize_t read(uint32_t *buffer, long sec, long usec) const; 00426 00432 ssize_t read(uint64_t *buffer, long sec, long usec) const; 00433 00439 ssize_t read(int16_t *buffer, long sec, long usec) const; 00440 00446 ssize_t read(int32_t *buffer, long sec, long usec) const; 00447 00453 ssize_t read(int64_t *buffer, long sec, long usec) const; 00454 00460 ssize_t read(float *buffer, long sec, long usec) const; 00461 00467 ssize_t read(double *buffer, long sec, long usec) const; 00468 00474 ssize_t read(unsigned char *buffer, 00475 long sec, long usec) const; 00476 00482 ssize_t read(char *buffer, long sec, long usec) const; 00483 00489 ssize_t read(bool *buffer, long sec, long usec) const; 00490 00496 ssize_t read(unsigned char *buffer, size_t size, 00497 long sec, long usec) const; 00498 00504 ssize_t read(char *buffer, size_t size, 00505 long sec, long usec) const; 00506 00512 ssize_t read(void *buf, size_t size, 00513 long sec, long usec) const; 00514 00524 ssize_t read(char **buffer, const char *terminator, 00525 long sec, long usec) const; 00526 00527 00551 int32_t waitForNonBlockingRead(long sec, long usec) const; 00552 00577 int32_t waitForNonBlockingWrite(long sec, long usec) const; 00578 00579 00584 void retryInterruptedReads(); 00585 00591 void dontRetryInterruptedReads(); 00592 00597 void retryInterruptedWrites(); 00598 00604 void dontRetryInterruptedWrites(); 00605 00611 void retryInterruptedWaits(); 00612 00618 void dontRetryInterruptedWaits(); 00619 00625 void retryInterruptedFcntl(); 00626 00632 void dontRetryInterruptedFcntl(); 00633 00639 void retryInterruptedIoctl(); 00640 00646 void dontRetryInterruptedIoctl(); 00647 00648 00659 void allowShortReads(); 00660 00666 void dontAllowShortReads(); 00667 00679 void allowShortWrites(); 00680 00686 void dontAllowShortWrites(); 00687 00697 void useListener(listener *lstnr); 00698 00705 void dontUseListener(); 00706 00709 listener *getListener(); 00710 00714 void useListenerInsideReads(); 00715 00719 void dontUseListenerInsideReads(); 00720 00724 void useListenerInsideWrites(); 00725 00729 void dontUseListenerInsideWrites(); 00730 00731 00735 virtual bool passFileDescriptor(int32_t fd) const; 00736 00740 virtual bool receiveFileDescriptor(int32_t *fd) const; 00741 00745 void translateByteOrder(); 00746 00750 void dontTranslateByteOrder(); 00751 00754 int32_t fCntl(int32_t command, long arg) const; 00755 00758 int32_t ioCtl(int32_t command, void *arg) const; 00759 00768 bool useNaglesAlgorithm(); 00769 00774 bool dontUseNaglesAlgorithm(); 00775 00780 bool setTcpWriteBufferSize(int32_t size); 00781 00786 bool getTcpWriteBufferSize(int32_t *size); 00787 00792 bool setTcpReadBufferSize(int32_t size); 00793 00798 bool getTcpReadBufferSize(int32_t *size); 00799 00804 const char *getType() const; 00805 00812 char *getPeerAddress() const; 00813 00814 00836 bool setWriteBufferSize(ssize_t size) const; 00837 00864 bool flushWriteBuffer(long sec, long usec) const; 00865 00866 00886 bool setReadBufferSize(ssize_t size) const; 00887 00893 bool closeOnExec(); 00894 00901 bool dontCloseOnExec(); 00902 00909 bool getCloseOnExec(); 00910 00913 static uint16_t hostToNet(uint16_t value); 00914 00917 static uint32_t hostToNet(uint32_t value); 00918 00921 static uint64_t hostToNet(uint64_t value); 00922 00925 static uint16_t netToHost(uint16_t value); 00926 00929 static uint32_t netToHost(uint32_t value); 00930 00933 static uint64_t netToHost(uint64_t value); 00934 00935 #include <rudiments/private/filedescriptor.h> 00936 }; 00937 00938 #ifdef RUDIMENTS_NAMESPACE 00939 } 00940 #endif 00941 00942 #endif