00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef SOCKETUNIX_H
00011 #define SOCKETUNIX_H
00012
00013 #include <iostream>
00014 #include <cstring>
00015 #include <string>
00016 #include <unistd.h>
00017 #include <fcntl.h>
00018
00019 #include "ComPlusPlus/Socket.h"
00020
00021
00022 namespace compp {
00023
00024 enum UDSTYPE { STREAM, DATAGRAM };
00025
00030 class SocketUnix : public Socket {
00031
00032 private:
00033 void NewUnixSocket(enum UDSTYPE ST );
00034
00035 protected:
00036
00037 std::string ownAddress;
00038 std::string otherAddress;
00039 enum UDSTYPE STYP;
00040
00041 void _MkSockaddrUnix( const std::string &fn, struct sockaddr_un *ad );
00042
00043 public:
00044
00045 ~SocketUnix();
00046 SocketUnix(enum UDSTYPE ST = STREAM, unsigned int buffsz = SocketUnixStandardBufferSize);
00047 SocketUnix(const std::string & fn, enum UDSTYPE ST = STREAM, unsigned int buffsz = SocketUnixStandardBufferSize);
00048 SocketUnix(int lfd, sockaddr_un *u, size_t l, unsigned int readaheadbufsize = SocketUnixStandardBufferSize) ;
00049 void Shutdown (int method = 0);
00050
00051 void Close ();
00052
00053
00054 void Listen ( const int backlog = 5);
00055
00056
00057 void Bind ( const std::string & fn);
00058
00059 bool Connect( const std::string &fn );
00060 SocketUnix* Accept ( void );
00061
00062
00063 int Sendto(const void *buf, size_t len, const std::string &fn);
00064
00065
00066 int Recvfrom(void *buf, int len, int flags, std::string &path);
00067
00068 static const unsigned int SocketUnixStandardBufferSize = (8*1024);
00069
00070 };
00071 }
00072 #endif
00073
00074