00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_VECTORIO_H
00014 #define _SUPPORT_VECTORIO_H
00015
00021 #include <support/SupportDefs.h>
00022
00023 #include <sys/uio.h>
00024
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace support {
00028 #endif
00029
00030
00031
00032
00037 class SVectorIO
00038 {
00039 public:
00040 SVectorIO();
00041 virtual ~SVectorIO();
00042
00043 const iovec* Vectors() const;
00044 inline operator const iovec*() const { return Vectors(); }
00045
00046 ssize_t CountVectors() const;
00047 size_t DataLength() const;
00048
00049 ssize_t AddVector(void* base, size_t length);
00050 ssize_t AddVector(const iovec* vector, size_t count = 1);
00051 void* Allocate(size_t length);
00052
00053 void MakeEmpty();
00054 void SetError(status_t err);
00055
00056 ssize_t Write(void* buffer, size_t avail) const;
00057 ssize_t Read(const void* buffer, size_t avail) const;
00058
00059 private:
00060
00061 virtual status_t _ReservedVectorIO1();
00062 virtual status_t _ReservedVectorIO2();
00063 virtual status_t _ReservedVectorIO3();
00064 virtual status_t _ReservedVectorIO4();
00065 virtual status_t _ReservedVectorIO5();
00066 virtual status_t _ReservedVectorIO6();
00067 virtual status_t _ReservedVectorIO7();
00068 virtual status_t _ReservedVectorIO8();
00069 virtual status_t _ReservedVectorIO9();
00070 virtual status_t _ReservedVectorIO10();
00071
00072 SVectorIO(const SVectorIO& o);
00073 SVectorIO& operator=(const SVectorIO& o);
00074
00075 enum {
00076 MAX_LOCAL_VECTOR = 16,
00077 MAX_LOCAL_DATA = 256
00078 };
00079
00080 struct alloc_data {
00081 size_t size;
00082 size_t next_pos;
00083 };
00084
00085 iovec m_localVector[MAX_LOCAL_VECTOR];
00086 SVector<iovec>* m_heapVector;
00087 ssize_t m_vectorCount;
00088 size_t m_totalLength;
00089
00090 alloc_data m_localData;
00091 uint8_t m_localDataBuffer[MAX_LOCAL_DATA];
00092 SVector<alloc_data*>* m_heapData;
00093 };
00094
00097 #if _SUPPORTS_NAMESPACE
00098 } }
00099 #endif
00100
00101 #endif