From: Mikko Rasa Date: Mon, 1 Aug 2011 11:36:50 +0000 (+0300) Subject: Style update: spaces around assignments X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a81c41acd873cda7f40bca634782230d9e57dc4f;p=libs%2Fnet.git Style update: spaces around assignments --- diff --git a/source/communicator.cpp b/source/communicator.cpp index 2b20c6e..1bb0fde 100644 --- a/source/communicator.cpp +++ b/source/communicator.cpp @@ -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); } diff --git a/source/communicator.h b/source/communicator.h index 865e05d..4bd5409 100644 --- a/source/communicator.h +++ b/source/communicator.h @@ -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); } diff --git a/source/constants.h b/source/constants.h index 2edb643..4feefcc 100644 --- a/source/constants.h +++ b/source/constants.h @@ -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 diff --git a/source/datagramsocket.cpp b/source/datagramsocket.cpp index 43b8661..714b4d5 100644 --- a/source/datagramsocket.cpp +++ b/source/datagramsocket.cpp @@ -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(&sa), size); + int err = ::connect(handle, reinterpret_cast(&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(&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(&addr), addr_len); + int ret = ::sendto(handle, buf, size, 0, reinterpret_cast(&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(&addr), &addr_len); + int ret = ::recvfrom(handle, buf, size, 0, reinterpret_cast(&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; } diff --git a/source/datagramsocket.h b/source/datagramsocket.h index 8c08a5d..3903a6a 100644 --- a/source/datagramsocket.h +++ b/source/datagramsocket.h @@ -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 *&); diff --git a/source/inet.cpp b/source/inet.cpp index cb34263..962899b 100644 --- a/source/inet.cpp +++ b/source/inet.cpp @@ -23,7 +23,7 @@ InetAddr::InetAddr(in_addr_t a, in_port_t p): string InetAddr::str() const { - const unsigned char *ptr=reinterpret_cast(&addr); + const unsigned char *ptr = reinterpret_cast(&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(sa); - sai.sin_family=AF_INET; - sai.sin_addr.s_addr=addr; - sai.sin_port=port; + sockaddr_in &sai = reinterpret_cast(sa); + sai.sin_family = AF_INET; + sai.sin_addr.s_addr = addr; + sai.sin_port = port; return sizeof(sockaddr_in); } diff --git a/source/protocol.cpp b/source/protocol.cpp index a438699..147077c 100644 --- a/source/protocol.cpp +++ b/source/protocol.cpp @@ -27,12 +27,12 @@ template char *Assembler::assemble(const T &v, char *data, char *end) { // XXX Assumes little-endian - const char *ptr=reinterpret_cast(&v)+sizeof(T); + const char *ptr = reinterpret_cast(&v)+sizeof(T); for(unsigned i=0; i::assemble(const T &v, char *data, char *end) template<> char *Assembler::assemble(const string &v, char *data, char *end) { - data=Assembler::assemble(v.size(), data, end); + data = Assembler::assemble(v.size(), data, end); if(end-data(v.size())) throw Msp::Exception("Out of buffer space"); memcpy(data, v.data(), v.size()); @@ -50,21 +50,21 @@ char *Assembler::assemble(const string &v, char *data, char *end) template char *Assembler >::assemble(const vector &v, char *data, char *end) { - data=Assembler::assemble(v.size(), data, end); + data = Assembler::assemble(v.size(), data, end); for(typename vector::const_iterator i=v.begin(); i!=v.end(); ++i) - data=Assembler::assemble(*i, data, end); + data = Assembler::assemble(*i, data, end); return data; } template const char *Assembler::disassemble(T &v, const char *data, const char *end) { - char *ptr=reinterpret_cast(&v)+sizeof(T); + char *ptr = reinterpret_cast(&v)+sizeof(T); for(unsigned i=0; i const char *Assembler::disassemble(string &v, const char *data, const char *end) { unsigned short size; - data=Assembler::disassemble(size, data, end); + data = Assembler::disassemble(size, data, end); if(end-data >::disassemble(vector &v, const char *data, c only code path leading here is from PacketDef

::disassemble, which creates a new packet. */ unsigned short size; - data=Assembler::disassemble(size, data, end); + data = Assembler::disassemble(size, data, end); for(unsigned i=0; i::disassemble(u, data, end); + data = Assembler::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(data); - unsigned id=(udata[0]<<8)+udata[1]; - unsigned psz=(udata[2]<<8)+udata[3]; + const unsigned char *udata = reinterpret_cast(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(data); + const unsigned char *udata = reinterpret_cast(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 @@ -229,7 +229,7 @@ template const char *Protocol::disassemble_field<>(vector &v, const char template const char *Protocol::disassemble_field<>(vector &v, const char *d, const char *e); template const char *Protocol::disassemble_field<>(vector &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 diff --git a/source/protocol.h b/source/protocol.h index 8ae5cdd..4bde291 100644 --- a/source/protocol.h +++ b/source/protocol.h @@ -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 @@ -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 *>::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

*prcv=dynamic_cast *>(&r); + PacketReceiver

*prcv = dynamic_cast *>(&r); if(!prcv) throw Exception("Packet type not supported by receiver"); P pkt; for(typename std::vector *>::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 PacketDef

&add() { - PacketDef

*pdef=new PacketDef

(next_packet_id++); + PacketDef

*pdef = new PacketDef

(next_packet_id++); add_packet(*pdef); return *pdef; } @@ -128,10 +128,10 @@ public: template unsigned assemble(const P &pkt, char *buf, unsigned size) const { - unsigned id=PacketDef

::class_id; - const PacketDef

&pdef=static_cast &>(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

::class_id; + const PacketDef

&pdef = static_cast &>(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 -unsigned Protocol::PacketDef

::class_id=0; +unsigned Protocol::PacketDef

::class_id = 0; } // namespace Net } // namespace Msp diff --git a/source/receiver.h b/source/receiver.h index 99ad8a0..19e69e0 100644 --- a/source/receiver.h +++ b/source/receiver.h @@ -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 diff --git a/source/resolve.cpp b/source/resolve.cpp index 5bdf051..e732fc0 100644 --- a/source/resolve.cpp +++ b/source/resolve.cpp @@ -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 diff --git a/source/resolve.h b/source/resolve.h index 4731969..0afc9ad 100644 --- a/source/resolve.h +++ b/source/resolve.h @@ -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 diff --git a/source/sockaddr.h b/source/sockaddr.h index 62e559c..745e6d4 100644 --- a/source/sockaddr.h +++ b/source/sockaddr.h @@ -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; diff --git a/source/socket.cpp b/source/socket.cpp index dd6c526..2cc3d88 100644 --- a/source/socket.cpp +++ b/source/socket.cpp @@ -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: "<(&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(&sa), size); + int err = ::bind(handle, reinterpret_cast(&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); } diff --git a/source/socket.h b/source/socket.h index caea924..d48f350 100644 --- a/source/socket.h +++ b/source/socket.h @@ -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; diff --git a/source/streamlistensocket.cpp b/source/streamlistensocket.cpp index 88a37bf..68580d7 100644 --- a/source/streamlistensocket.cpp +++ b/source/streamlistensocket.cpp @@ -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(&sa), &size); + socklen_t size = sizeof(sockaddr_storage); + SocketHandle new_h = ::accept(handle, reinterpret_cast(&sa), &size); - RefPtr paddr=SockAddr::create(sa); + RefPtr paddr = SockAddr::create(sa); return new StreamSocket(new_h, *paddr); } diff --git a/source/streamlistensocket.h b/source/streamlistensocket.h index 3defb30..8b96a98 100644 --- a/source/streamlistensocket.h +++ b/source/streamlistensocket.h @@ -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; diff --git a/source/streamsocket.cpp b/source/streamsocket.cpp index 79b08f4..c5e1968 100644 --- a/source/streamsocket.cpp +++ b/source/streamsocket.cpp @@ -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(&sa), size, 0, 0, 0, 0); + int err = WSAConnect(handle, reinterpret_cast(&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(&sa), size); + int err = ::connect(handle, reinterpret_cast(&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(&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 diff --git a/source/streamsocket.h b/source/streamsocket.h index 6fbb7d5..66841de 100644 --- a/source/streamsocket.h +++ b/source/streamsocket.h @@ -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 &);