]> git.tdb.fi Git - libs/net.git/commitdiff
Style update: spaces around assignments
authorMikko Rasa <tdb@tdb.fi>
Mon, 1 Aug 2011 11:36:50 +0000 (14:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 1 Aug 2011 12:12:01 +0000 (15:12 +0300)
18 files changed:
source/communicator.cpp
source/communicator.h
source/constants.h
source/datagramsocket.cpp
source/datagramsocket.h
source/inet.cpp
source/protocol.cpp
source/protocol.h
source/receiver.h
source/resolve.cpp
source/resolve.h
source/sockaddr.h
source/socket.cpp
source/socket.h
source/streamlistensocket.cpp
source/streamlistensocket.h
source/streamsocket.cpp
source/streamsocket.h

index 2b20c6ec374932b993d70b2b5e6df4ea9745f59f..1bb0fde49592f81d9f9c2fa91a22a52431f45e7a 100644 (file)
@@ -41,7 +41,7 @@ HandshakeReceiver::HandshakeReceiver():
 
 void HandshakeReceiver::receive(const Handshake &shake)
 {
-       hash=shake.hash;
+       hash = shake.hash;
 }
 
 }
@@ -76,32 +76,32 @@ void Communicator::initiate_handshake()
                throw InvalidState("Handshaking is already underway or done");
 
        send_handshake();
-       handshake_status=1;
+       handshake_status = 1;
 }
 
 void Communicator::data_available()
 {
-       in_end+=socket.read(in_end, in_buf+buf_size-in_end);
+       in_end += socket.read(in_end, in_buf+buf_size-in_end);
        try
        {
-               bool more=true;
+               bool more = true;
                while(more)
                {
                        if(handshake_status==2)
                        {
-                               more=receive_packet(protocol, receiver);
+                               more = receive_packet(protocol, receiver);
                        }
                        else
                        {
                                HandshakeProtocol hsproto;
                                HandshakeReceiver hsrecv;
-                               if((more=receive_packet(hsproto, hsrecv)))
+                               if((more = receive_packet(hsproto, hsrecv)))
                                {
                                        if(hsrecv.get_hash()==protocol.get_hash())
                                        {
                                                if(handshake_status==0)
                                                        send_handshake();
-                                               handshake_status=2;
+                                               handshake_status = 2;
                                                signal_handshake_done.emit();
                                        }
                                        else
@@ -119,11 +119,11 @@ void Communicator::data_available()
 
 bool Communicator::receive_packet(const Protocol &proto, ReceiverBase &recv)
 {
-       int psz=proto.get_packet_size(in_begin, in_end-in_begin);
+       int psz = proto.get_packet_size(in_begin, in_end-in_begin);
        if(psz && psz<=in_end-in_begin)
        {
-               char *pkt=in_begin;
-               in_begin+=psz;
+               char *pkt = in_begin;
+               in_begin += psz;
                proto.disassemble(recv, pkt, psz);
                return true;
        }
@@ -131,10 +131,10 @@ bool Communicator::receive_packet(const Protocol &proto, ReceiverBase &recv)
        {
                if(in_end==in_buf+buf_size)
                {
-                       unsigned used=in_end-in_begin;
+                       unsigned used = in_end-in_begin;
                        memmove(in_buf, in_begin, used);
-                       in_begin=in_buf;
-                       in_end=in_begin+used;
+                       in_begin = in_buf;
+                       in_end = in_begin+used;
                }
                return false;
        }
@@ -143,10 +143,10 @@ bool Communicator::receive_packet(const Protocol &proto, ReceiverBase &recv)
 void Communicator::send_handshake()
 {
        Handshake shake;
-       shake.hash=protocol.get_hash();
+       shake.hash = protocol.get_hash();
 
        HandshakeProtocol hsproto;
-       unsigned size=hsproto.assemble(shake, out_buf, buf_size);
+       unsigned size = hsproto.assemble(shake, out_buf, buf_size);
        socket.write(out_buf, size);
 }
 
index 865e05dcfe429b4e28a05eb11b180b394771f233..4bd5409c72587dfc9dbe9b98e43e04b0bbdf5d27 100644 (file)
@@ -35,7 +35,7 @@ public:
        {
                if(handshake_status!=2)
                        throw InvalidState("Handshaking is not done");
-               unsigned size=protocol.assemble(pkt, out_buf, buf_size);
+               unsigned size = protocol.assemble(pkt, out_buf, buf_size);
                socket.write(out_buf, size);
        }
 
index 2edb643734307be2223e8433dc25729d22247a04..4feefcc25c46fe50628454cfc5895f4db82225ff 100644 (file)
@@ -12,10 +12,10 @@ namespace Net {
 
 enum Family
 {
-       UNSPEC=AF_UNSPEC,
-       INET=AF_INET,
-       INET6=AF_INET6,
-       UNIF=AF_UNIX
+       UNSPEC = AF_UNSPEC,
+       INET = AF_INET,
+       INET6 = AF_INET6,
+       UNIF = AF_UNIX
 };
 
 } // namespace Net
index 43b86615b2ee2e631cef68be878c69299f73701e..714b4d58df67a1d8af548bdd957716350644b5a2 100644 (file)
@@ -19,21 +19,21 @@ int DatagramSocket::connect(const SockAddr &addr)
        check_state(false);
 
        sockaddr_storage sa;
-       socklen_t size=addr.fill_sockaddr(sa);
+       socklen_t size = addr.fill_sockaddr(sa);
 
-       int err=::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
+       int err = ::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
        if(err==-1)
                throw SystemError("Unable to connect", errno);
 
        delete peer_addr;
-       peer_addr=addr.copy();
+       peer_addr = addr.copy();
 
        delete local_addr;
-       size=sizeof(sockaddr_storage);
+       size = sizeof(sockaddr_storage);
        getsockname(handle, reinterpret_cast<sockaddr *>(&sa), &size);
-       local_addr=SockAddr::create(sa);
+       local_addr = SockAddr::create(sa);
 
-       connected=true;
+       connected = true;
 
        return (err==0)?0:1;
 }
@@ -46,9 +46,9 @@ unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &
                return 0;
 
        sockaddr_storage addr;
-       socklen_t addr_len=addr_.fill_sockaddr(addr);
+       socklen_t addr_len = addr_.fill_sockaddr(addr);
 
-       int ret=::sendto(handle, buf, size, 0, reinterpret_cast<sockaddr *>(&addr), addr_len);
+       int ret = ::sendto(handle, buf, size, 0, reinterpret_cast<sockaddr *>(&addr), addr_len);
        if(ret<0)
        {
                if(errno==EAGAIN)
@@ -68,9 +68,9 @@ unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&addr_)
                return 0;
 
        sockaddr_storage addr;
-       socklen_t addr_len=sizeof(sockaddr_storage);
+       socklen_t addr_len = sizeof(sockaddr_storage);
 
-       int ret=::recvfrom(handle, buf, size, 0, reinterpret_cast<sockaddr *>(&addr), &addr_len);
+       int ret = ::recvfrom(handle, buf, size, 0, reinterpret_cast<sockaddr *>(&addr), &addr_len);
        if(ret<0)
        {
                if(errno==EAGAIN)
@@ -79,7 +79,7 @@ unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&addr_)
                        throw SystemError("Recvfrom failed", errno);
        }
 
-       addr_=SockAddr::create(addr);
+       addr_ = SockAddr::create(addr);
 
        return ret;
 }
index 8c08a5d090b69190ef19f18a3970af762646ae6e..3903a6afa8e65ace8e7cdf15ba904c61082278fb 100644 (file)
@@ -9,7 +9,8 @@ namespace Net {
 class DatagramSocket: public Socket
 {
 public:
-       DatagramSocket(Family, int =0);
+       DatagramSocket(Family, int = 0);
+
        int connect(const SockAddr &);
        unsigned sendto(const char *, unsigned, const SockAddr &);
        unsigned recvfrom(char *, unsigned, SockAddr *&);
index cb34263fc1de38230edcae058ca014ba671e5858..962899bfbdebaf75253ff38cff67b95899b48fd7 100644 (file)
@@ -23,7 +23,7 @@ InetAddr::InetAddr(in_addr_t a, in_port_t p):
 
 string InetAddr::str() const
 {
-       const unsigned char *ptr=reinterpret_cast<const unsigned char *>(&addr);
+       const unsigned char *ptr = reinterpret_cast<const unsigned char *>(&addr);
        string result = format("%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);
        if(port)
                result += format(":%d", ntohs(port));
@@ -32,10 +32,10 @@ string InetAddr::str() const
 
 unsigned InetAddr::fill_sockaddr(sockaddr &sa) const
 {
-       sockaddr_in &sai=reinterpret_cast<sockaddr_in &>(sa);
-       sai.sin_family=AF_INET;
-       sai.sin_addr.s_addr=addr;
-       sai.sin_port=port;
+       sockaddr_in &sai = reinterpret_cast<sockaddr_in &>(sa);
+       sai.sin_family = AF_INET;
+       sai.sin_addr.s_addr = addr;
+       sai.sin_port = port;
 
        return sizeof(sockaddr_in);
 }
index a4386994d06b84af59e2efaa99b226959b456d96..147077cc1253c3c60e7c9ab049951b0e3223445b 100644 (file)
@@ -27,12 +27,12 @@ template<typename T>
 char *Assembler<T>::assemble(const T &v, char *data, char *end)
 {
        // XXX Assumes little-endian
-       const char *ptr=reinterpret_cast<const char *>(&v)+sizeof(T);
+       const char *ptr = reinterpret_cast<const char *>(&v)+sizeof(T);
        for(unsigned i=0; i<sizeof(T); ++i)
        {
                if(data==end)
                        throw Msp::Exception("Out of buffer space");
-               *data++=*--ptr;
+               *data++ = *--ptr;
        }
        return data;
 }
@@ -40,7 +40,7 @@ char *Assembler<T>::assemble(const T &v, char *data, char *end)
 template<>
 char *Assembler<string>::assemble(const string &v, char *data, char *end)
 {
-       data=Assembler<unsigned short>::assemble(v.size(), data, end);
+       data = Assembler<unsigned short>::assemble(v.size(), data, end);
        if(end-data<static_cast<int>(v.size()))
                throw Msp::Exception("Out of buffer space");
        memcpy(data, v.data(), v.size());
@@ -50,21 +50,21 @@ char *Assembler<string>::assemble(const string &v, char *data, char *end)
 template<typename T>
 char *Assembler<vector<T> >::assemble(const vector<T> &v, char *data, char *end)
 {
-       data=Assembler<unsigned short>::assemble(v.size(), data, end);
+       data = Assembler<unsigned short>::assemble(v.size(), data, end);
        for(typename vector<T>::const_iterator i=v.begin(); i!=v.end(); ++i)
-               data=Assembler<T>::assemble(*i, data, end);
+               data = Assembler<T>::assemble(*i, data, end);
        return data;
 }
 
 template<typename T>
 const char *Assembler<T>::disassemble(T &v, const char *data, const char *end)
 {
-       char *ptr=reinterpret_cast<char *>(&v)+sizeof(T);
+       char *ptr = reinterpret_cast<char *>(&v)+sizeof(T);
        for(unsigned i=0; i<sizeof(T); ++i)
        {
                if(data==end)
                        throw Msp::Exception("Premature end of data");
-               *--ptr=*data++;
+               *--ptr = *data++;
        }
        return data;
 }
@@ -73,7 +73,7 @@ template<>
 const char *Assembler<string>::disassemble(string &v, const char *data, const char *end)
 {
        unsigned short size;
-       data=Assembler<unsigned short>::disassemble(size, data, end);
+       data = Assembler<unsigned short>::disassemble(size, data, end);
        if(end-data<size)
                throw Msp::Exception("Premature end of data");
        v.assign(data, data+size);
@@ -87,11 +87,11 @@ const char *Assembler<vector<T> >::disassemble(vector<T> &v, const char *data, c
        only code path leading here is from PacketDef<P>::disassemble, which creates
        a new packet. */
        unsigned short size;
-       data=Assembler<unsigned short>::disassemble(size, data, end);
+       data = Assembler<unsigned short>::disassemble(size, data, end);
        for(unsigned i=0; i<size; ++i)
        {
                T u;
-               data=Assembler<T>::disassemble(u, data, end);
+               data = Assembler<T>::disassemble(u, data, end);
                v.push_back(u);
        }
        return data;
@@ -114,16 +114,16 @@ Protocol::~Protocol()
 
 void Protocol::add_packet(PacketDefBase &pdef)
 {
-       PacketDefBase *&ptr=packet_class_defs[pdef.get_class_id()];
+       PacketDefBase *&ptr = packet_class_defs[pdef.get_class_id()];
        if(ptr)
                delete ptr;
-       ptr=&pdef;
-       packet_id_defs[pdef.get_id()]=&pdef;
+       ptr = &pdef;
+       packet_id_defs[pdef.get_id()] = &pdef;
 }
 
 const Protocol::PacketDefBase &Protocol::get_packet_by_class(unsigned id) const
 {
-       PacketMap::const_iterator i=packet_class_defs.find(id);
+       PacketMap::const_iterator i = packet_class_defs.find(id);
        if(i==packet_class_defs.end())
                throw KeyError("Unknown packet class", lexical_cast(id));
        return *i->second;
@@ -131,7 +131,7 @@ const Protocol::PacketDefBase &Protocol::get_packet_by_class(unsigned id) const
 
 const Protocol::PacketDefBase &Protocol::get_packet_by_id(unsigned id) const
 {
-       PacketMap::const_iterator i=packet_id_defs.find(id);
+       PacketMap::const_iterator i = packet_id_defs.find(id);
        if(i==packet_id_defs.end())
                throw KeyError("Unknown packet ID", lexical_cast(id));
        return *i->second;
@@ -139,13 +139,13 @@ const Protocol::PacketDefBase &Protocol::get_packet_by_id(unsigned id) const
 
 unsigned Protocol::disassemble(ReceiverBase &rcv, const char *data, unsigned size) const
 {
-       const unsigned char *udata=reinterpret_cast<const unsigned char *>(data);
-       unsigned id=(udata[0]<<8)+udata[1];
-       unsigned psz=(udata[2]<<8)+udata[3];
+       const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
+       unsigned id = (udata[0]<<8)+udata[1];
+       unsigned psz = (udata[2]<<8)+udata[3];
        if(psz>size)
                throw InvalidParameterValue("Not enough data for packet");
-       const PacketDefBase &pdef=get_packet_by_id(id);
-       const char *ptr=pdef.disassemble(rcv, data+4, data+psz);
+       const PacketDefBase &pdef = get_packet_by_id(id);
+       const char *ptr = pdef.disassemble(rcv, data+4, data+psz);
        return ptr-data;
 }
 
@@ -153,7 +153,7 @@ unsigned Protocol::get_packet_size(const char *data, unsigned size) const
 {
        if(size<4)
                return 0;
-       const unsigned char *udata=reinterpret_cast<const unsigned char *>(data);
+       const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
        return (udata[2]<<8)+udata[3];
 }
 
@@ -165,10 +165,10 @@ unsigned Protocol::get_hash() const
 
 void Protocol::assemble_header(char *buf, unsigned id, unsigned size)
 {
-       buf[0]=(id>>8)&0xFF;
-       buf[1]=id&0xFF;
-       buf[2]=(size>>8)&0xFF;
-       buf[3]=size&0xFF;
+       buf[0] = (id>>8)&0xFF;
+       buf[1] = id&0xFF;
+       buf[2] = (size>>8)&0xFF;
+       buf[3] = size&0xFF;
 }
 
 template<typename T>
@@ -229,7 +229,7 @@ template const char *Protocol::disassemble_field<>(vector<float> &v, const char
 template const char *Protocol::disassemble_field<>(vector<double> &v, const char *d, const char *e);
 template const char *Protocol::disassemble_field<>(vector<string> &v, const char *d, const char *e);
 
-unsigned Protocol::PacketDefBase::next_class_id=1;
+unsigned Protocol::PacketDefBase::next_class_id = 1;
 
 } // namespace Net
 } // namespace Msp
index 8ae5cdd149170c0bfdc0e5dcf3342e226ff27946..4bde291ea5c263ce519ea4cac690a6120758fc92 100644 (file)
@@ -20,9 +20,9 @@ private:
                PacketDefBase(unsigned i): id(i) { }
        public:
                virtual ~PacketDefBase() { }
-               virtual unsigned get_class_id() const =0;
+               virtual unsigned get_class_id() const = 0;
                unsigned get_id() const { return id; }
-               virtual const char *disassemble(ReceiverBase &, const char *, const char *) const =0;
+               virtual const char *disassemble(ReceiverBase &, const char *, const char *) const = 0;
 
                static unsigned next_class_id;
        };
@@ -34,8 +34,8 @@ private:
                FieldBase() { }
        public:
                virtual ~FieldBase() { }
-               virtual char *assemble(const P &, char *, char *) const =0;
-               virtual const char *disassemble(P &, const char *, const char *) const =0;
+               virtual char *assemble(const P &, char *, char *) const = 0;
+               virtual const char *disassemble(P &, const char *, const char *) const = 0;
        };
 
        template<typename P, typename T>
@@ -63,7 +63,7 @@ protected:
 
        public:
                PacketDef(unsigned i): PacketDefBase(i)
-               { if(!class_id) class_id=next_class_id++; }
+               { if(!class_id) class_id = next_class_id++; }
 
                ~PacketDef()
                {
@@ -80,18 +80,18 @@ protected:
                char *assemble(const P &p, char *d, char *e) const
                {
                        for(typename std::vector<FieldBase<P> *>::const_iterator i=fields.begin(); i!=fields.end(); ++i)
-                               d=(*i)->assemble(p, d, e);
+                               d = (*i)->assemble(p, d, e);
                        return d;
                }
 
                const char *disassemble(ReceiverBase &r, const char *d, const char *e) const
                {
-                       PacketReceiver<P> *prcv=dynamic_cast<PacketReceiver<P> *>(&r);
+                       PacketReceiver<P> *prcv = dynamic_cast<PacketReceiver<P> *>(&r);
                        if(!prcv)
                                throw Exception("Packet type not supported by receiver");
                        P pkt;
                        for(typename std::vector<FieldBase<P> *>::const_iterator i=fields.begin(); i!=fields.end(); ++i)
-                               d=(*i)->disassemble(pkt, d, e);
+                               d = (*i)->disassemble(pkt, d, e);
                        prcv->receive(pkt);
                        return d;
                }
@@ -105,7 +105,7 @@ protected:
        PacketMap packet_class_defs;
        PacketMap packet_id_defs;
 
-       Protocol(unsigned =1);
+       Protocol(unsigned = 1);
 public:
        ~Protocol();
 
@@ -116,7 +116,7 @@ protected:
        template<typename P>
        PacketDef<P> &add()
        {
-               PacketDef<P> *pdef=new PacketDef<P>(next_packet_id++);
+               PacketDef<P> *pdef = new PacketDef<P>(next_packet_id++);
                add_packet(*pdef);
                return *pdef;
        }
@@ -128,10 +128,10 @@ public:
        template<typename P>
        unsigned assemble(const P &pkt, char *buf, unsigned size) const
        {
-               unsigned id=PacketDef<P>::class_id;
-               const PacketDef<P> &pdef=static_cast<const PacketDef<P> &>(get_packet_by_class(id));
-               char *ptr=pdef.assemble(pkt, buf+4, buf+size);
-               assemble_header(buf, pdef.get_id(), (size=ptr-buf));
+               unsigned id = PacketDef<P>::class_id;
+               const PacketDef<P> &pdef = static_cast<const PacketDef<P> &>(get_packet_by_class(id));
+               char *ptr = pdef.assemble(pkt, buf+4, buf+size);
+               assemble_header(buf, pdef.get_id(), (size = ptr-buf));
                return size;
        }
 
@@ -152,7 +152,7 @@ private:
 };
 
 template<typename P>
-unsigned Protocol::PacketDef<P>::class_id=0;
+unsigned Protocol::PacketDef<P>::class_id = 0;
 
 } // namespace Net
 } // namespace Msp
index 99ad8a0cb57be13d5946d2c079fe728922a4821d..19e69e0d4c5926ceaa9c23ec518731fdcc82fcf3 100644 (file)
@@ -18,7 +18,7 @@ class PacketReceiver: public virtual ReceiverBase
 protected:
        PacketReceiver() { }
 public:
-       virtual void receive(const P &) =0;
+       virtual void receive(const P &) = 0;
 };
 
 } // namespace Net
index 5bdf051b16ebc4892769a2541ed133a8941647ec..e732fc040dfe037334cd203dc19fb2fc88f93906 100644 (file)
@@ -36,14 +36,14 @@ SockAddr *resolve(const string &s, Family family)
                        host = s;
        }
 
-       addrinfo hints={0, family, 0, 0, 0, 0, 0, 0};
+       addrinfo hints = {0, family, 0, 0, 0, 0, 0, 0};
        addrinfo *res;
-       const char *chost=(host.empty() ? 0 : host.c_str());
-       const char *cserv=(serv.empty() ? 0 : serv.c_str());
-       int err=getaddrinfo(chost, cserv, &hints, &res);
+       const char *chost = (host.empty() ? 0 : host.c_str());
+       const char *cserv = (serv.empty() ? 0 : serv.c_str());
+       int err = getaddrinfo(chost, cserv, &hints, &res);
        if(err==0)
        {
-               SockAddr *addr=SockAddr::create(*res->ai_addr);
+               SockAddr *addr = SockAddr::create(*res->ai_addr);
                freeaddrinfo(res);
                return addr;
        }
@@ -56,14 +56,14 @@ SockAddr *resolve(const string &s, Family family)
 }
 
                /*sockaddr sa;
-               unsigned size=fill_sockaddr(sa);
+               unsigned size = fill_sockaddr(sa);
                char hst[128];
                char srv[128];
-               int err=getnameinfo(&sa, size, hst, 128, srv, 128, 0);
+               int err = getnameinfo(&sa, size, hst, 128, srv, 128, 0);
                if(err==0)
                {
-                       host=hst;
-                       serv=srv;
+                       host = hst;
+                       serv = srv;
                }*/
 
 } // namespace Net
index 47319699010aca10b95c75813cec1bbc93438b34..0afc9adb78257c5a67c640e4665d5cae29f38995 100644 (file)
@@ -9,7 +9,7 @@ namespace Net {
 
 class SockAddr;
 
-SockAddr *resolve(const std::string &, Family =UNSPEC);
+SockAddr *resolve(const std::string &, Family = UNSPEC);
 
 } // namespace Net
 } // namespace Msp
index 62e559c23f73df62bde597d40ec1daee6668144a..745e6d45afc59adda0889843a257da05dbf16b24 100644 (file)
@@ -13,15 +13,15 @@ namespace Net {
 class SockAddr
 {
 public:
-       virtual Family get_family() const =0;
-       virtual std::string str() const =0;
+       virtual Family get_family() const = 0;
+       virtual std::string str() const = 0;
 
        /**
        Fills the given struct sockaddr with information from this SockAddr.
 
        @return  Number of bytes used
        */
-       virtual unsigned fill_sockaddr(sockaddr &) const =0;
+       virtual unsigned fill_sockaddr(sockaddr &) const = 0;
        virtual unsigned fill_sockaddr(sockaddr_storage &) const;
 
        virtual SockAddr *copy() const =0;
index dd6c526e994fdeb9dd5fc12da0ce9c9822608793..2cc3d88dbce4b2451909f5022b15008764bc7b2e 100644 (file)
@@ -17,7 +17,7 @@ public:
        WinSockHelper()
        {
                WSADATA wsa_data;
-               int err=WSAStartup(0x0002, &wsa_data);
+               int err = WSAStartup(0x0002, &wsa_data);
                if(err)
                        std::cerr<<"Failed to initialize WinSock: "<<err<<'\n';
        }
@@ -43,12 +43,12 @@ Socket::Socket(SocketHandle h, const SockAddr &paddr):
        peer_addr(paddr.copy())
 {
        sockaddr_storage sa;
-       socklen_t size=sizeof(sockaddr_storage);
+       socklen_t size = sizeof(sockaddr_storage);
        getsockname(handle, reinterpret_cast<sockaddr *>(&sa), &size);
-       local_addr=SockAddr::create(sa);
+       local_addr = SockAddr::create(sa);
 
 #ifdef WIN32
-       event=CreateEvent(0, false, false, 0);
+       event = CreateEvent(0, false, false, 0);
 #endif
 }
 
@@ -57,10 +57,10 @@ Socket::Socket(Family af, int type, int proto):
        local_addr(0),
        peer_addr(0)
 {
-       handle=socket(af, type, proto);
+       handle = socket(af, type, proto);
 
 #ifdef WIN32
-       event=CreateEvent(0, false, false, 0);
+       event = CreateEvent(0, false, false, 0);
 #endif
 }
 
@@ -71,15 +71,15 @@ Socket::~Socket()
 
 void Socket::set_block(bool b)
 {
-       mode=(mode&~IO::M_NONBLOCK);
+       mode = (mode&~IO::M_NONBLOCK);
        if(b)
-               mode=(mode|IO::M_NONBLOCK);
+               mode = (mode|IO::M_NONBLOCK);
 
 #ifdef WIN32
-       u_long flag=!b;
+       u_long flag = !b;
        ioctlsocket(handle, FIONBIO, &flag);
 #else
-       int flags=fcntl(handle, F_GETFL);
+       int flags = fcntl(handle, F_GETFL);
        fcntl(handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
 #endif
 }
@@ -99,14 +99,14 @@ void Socket::bind(const SockAddr &addr)
        check_state(false);
 
        sockaddr_storage sa;
-       unsigned size=addr.fill_sockaddr(sa);
+       unsigned size = addr.fill_sockaddr(sa);
 
-       int err=::bind(handle, reinterpret_cast<sockaddr *>(&sa), size);
+       int err = ::bind(handle, reinterpret_cast<sockaddr *>(&sa), size);
        if(err==-1)
                throw SystemError("Unable to bind", errno);
 
        delete local_addr;
-       local_addr=addr.copy();
+       local_addr = addr.copy();
 }
 
 /**
@@ -127,14 +127,14 @@ void Socket::close()
 #else
        ::close(handle);
 #endif
-       handle=MSP_NET_INVALID_SOCKET_HANDLE;
-       connected=false;
+       handle = MSP_NET_INVALID_SOCKET_HANDLE;
+       connected = false;
        signal_closed.emit();
 
        delete local_addr;
-       local_addr=0;
+       local_addr = 0;
        delete peer_addr;
-       peer_addr=0;
+       peer_addr = 0;
 }
 
 void Socket::set_timeout(const Time::TimeDelta &timeout)
@@ -198,7 +198,7 @@ unsigned Socket::do_write(const char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       int ret=::send(handle, buf, size, 0);
+       int ret = ::send(handle, buf, size, 0);
        if(ret<0)
        {
                if(errno==EAGAIN)
@@ -217,7 +217,7 @@ unsigned Socket::do_read(char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       int ret=::recv(handle, buf, size, 0);
+       int ret = ::recv(handle, buf, size, 0);
        if(ret<0)
        {
                if(errno==EAGAIN)
@@ -227,7 +227,7 @@ unsigned Socket::do_read(char *buf, unsigned size)
        }
        else if(ret==0 && !eof_flag)
        {
-               eof_flag=true;
+               eof_flag = true;
                signal_end_of_file.emit();
                set_events(IO::P_NONE);
        }
index caea92444a92cf12719c98cff3fbd6325f6b66ce..d48f3503bac63c7463c41bed46e5e93665f678f2 100644 (file)
@@ -30,7 +30,7 @@ public:
 
        bool is_connected() const { return connected; }
        void bind(const SockAddr &);
-       virtual int connect(const SockAddr &) =0;
+       virtual int connect(const SockAddr &) = 0;
        void close();
        void set_timeout(const Time::TimeDelta &);
        const SockAddr &get_local_address() const;
index 88a37bf73fb4f6bc3563788f05714b2c1a36350a..68580d7627672e7041e79f1a415d5c63d8c156eb 100644 (file)
@@ -21,7 +21,7 @@ void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
 {
        bind(addr);
 
-       int err=::listen(handle, backlog);
+       int err = ::listen(handle, backlog);
        if(err==-1)
                throw SystemError("Unable to listen", errno);
 
@@ -30,7 +30,7 @@ void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
 #endif
        set_events(IO::P_INPUT);
 
-       listening=true;
+       listening = true;
 }
 
 StreamSocket *StreamListenSocket::accept()
@@ -39,10 +39,10 @@ StreamSocket *StreamListenSocket::accept()
                throw InvalidState("Socket is not listening");
 
        sockaddr_storage sa;
-       socklen_t size=sizeof(sockaddr_storage);
-       SocketHandle new_h=::accept(handle, reinterpret_cast<sockaddr *>(&sa), &size);
+       socklen_t size = sizeof(sockaddr_storage);
+       SocketHandle new_h = ::accept(handle, reinterpret_cast<sockaddr *>(&sa), &size);
 
-       RefPtr<SockAddr> paddr=SockAddr::create(sa);
+       RefPtr<SockAddr> paddr = SockAddr::create(sa);
        return new StreamSocket(new_h, *paddr);
 }
 
index 3defb307c78a7f6786d69e85d48ce8d073e8d3ee..8b96a98441a619ce90366320905bc9911996fca4 100644 (file)
@@ -11,9 +11,9 @@ class StreamSocket;
 class StreamListenSocket: public Socket
 {
 public:
-       StreamListenSocket(Family, int =0);
+       StreamListenSocket(Family, int = 0);
        int connect(const SockAddr &);
-       void listen(const SockAddr &, unsigned =4);
+       void listen(const SockAddr &, unsigned = 4);
        StreamSocket *accept();
 private:
        bool listening;
index 79b08f4d91541854817d75f5f975f50444a21746..c5e19685f6f2cd615f6c34aa8532b045f7c691b2 100644 (file)
@@ -42,7 +42,7 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
        if(!connecting)
                throw InvalidState("No connection attempt going on");
 
-       int res=poll(*this, IO::P_OUTPUT, timeout);
+       int res = poll(*this, IO::P_OUTPUT, timeout);
        if(res==-1)
 #ifdef WIN32
                throw Exception(format("Connection polling failed: %d", WSAGetLastError()));
@@ -51,10 +51,10 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
 #endif
        else if(res>0)
        {
-               connecting=false;
+               connecting = false;
 
                int err;
-               socklen_t len=sizeof(int);
+               socklen_t len = sizeof(int);
                get_option(SOL_SOCKET, SO_ERROR, &err, &len);
 
                if(err!=0)
@@ -72,7 +72,7 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
 #endif
                set_events(IO::P_INPUT);
 
-               connected=true;
+               connected = true;
 
                return 0;
        }
@@ -96,16 +96,16 @@ int StreamSocket::connect(const SockAddr &addr)
                throw InvalidState("Socket is already connected");
 
        sockaddr_storage sa;
-       socklen_t size=addr.fill_sockaddr(sa);
+       socklen_t size = addr.fill_sockaddr(sa);
 
 #ifdef WIN32
-       int err=WSAConnect(handle, reinterpret_cast<sockaddr *>(&sa), size, 0, 0, 0, 0);
+       int err = WSAConnect(handle, reinterpret_cast<sockaddr *>(&sa), size, 0, 0, 0, 0);
        if(err==SOCKET_ERROR)
        {
-               int err_code=WSAGetLastError();
+               int err_code = WSAGetLastError();
                if(err_code==WSAEWOULDBLOCK)
                {
-                       connecting=true;
+                       connecting = true;
                        WSAEventSelect(handle, event, FD_CONNECT);
                        set_events(IO::P_OUTPUT);
                }
@@ -113,12 +113,12 @@ int StreamSocket::connect(const SockAddr &addr)
                        throw Exception(format("Unable to connect: %d", err_code));
        }
 #else
-       int err=::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
+       int err = ::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
        if(err==-1)
        {
                if(errno==EINPROGRESS)
                {
-                       connecting=true;
+                       connecting = true;
                        set_events(IO::P_OUTPUT);
                }
                else
@@ -127,16 +127,16 @@ int StreamSocket::connect(const SockAddr &addr)
 #endif
 
        delete peer_addr;
-       peer_addr=addr.copy();
+       peer_addr = addr.copy();
 
        delete local_addr;
-       size=sizeof(sockaddr_storage);
+       size = sizeof(sockaddr_storage);
        getsockname(handle, reinterpret_cast<sockaddr *>(&sa), &size);
-       local_addr=SockAddr::create(sa);
+       local_addr = SockAddr::create(sa);
 
        if(err==0)
        {
-               connected=true;
+               connected = true;
                set_events(IO::P_INPUT);
                signal_connect_finished.emit(0);
        }
@@ -150,17 +150,17 @@ void StreamSocket::on_event(IO::PollEvent ev)
        if((ev&(IO::P_OUTPUT|IO::P_ERROR)) && connecting)
        {
                int err;
-               socklen_t len=sizeof(err);
+               socklen_t len = sizeof(err);
                get_option(SOL_SOCKET, SO_ERROR, &err, &len);
 
-               connecting=false;
-               connected=(err==0);
+               connecting = false;
+               connected = (err==0);
                signal_connect_finished.emit(err);
 
                if(err!=0)
                {
                        delete peer_addr;
-                       peer_addr=0;
+                       peer_addr = 0;
                }
 
 #ifdef WIN32
index 6fbb7d5a79472e96368001abb7a57bf8a664c318..66841de0217f6fd5fb20dc6064c745980241ba47 100644 (file)
@@ -22,7 +22,7 @@ public:
 private:
        StreamSocket(SocketHandle, const SockAddr &);
 public:
-       StreamSocket(Family, int =0);
+       StreamSocket(Family, int = 0);
 
        bool is_connecting() const { return connecting; }
        int poll_connect(const Time::TimeDelta &);