Skip to content

Commit

Permalink
none
Browse files Browse the repository at this point in the history
  • Loading branch information
IronsDu committed Oct 17, 2018
1 parent d03e9ac commit 1ed5d98
Show file tree
Hide file tree
Showing 35 changed files with 90 additions and 198 deletions.
5 changes: 1 addition & 4 deletions src/brynet/net/Any.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _BRYNET_NET_ANY_H
#define _BRYNET_NET_ANY_H
#pragma once

#include <brynet/utils/CPP_VERSION.h>

Expand Down Expand Up @@ -31,5 +30,3 @@ namespace brynet
#endif
}
}

#endif
7 changes: 2 additions & 5 deletions src/brynet/net/Channel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_CHANNEL_H_
#define BRYNET_NET_CHANNEL_H_
#pragma once

namespace brynet
{
Expand All @@ -20,6 +19,4 @@ namespace brynet
friend class EventLoop;
};
}
}

#endif
}
26 changes: 11 additions & 15 deletions src/brynet/net/Connector.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#include <cassert>
#include <set>
#include <vector>
#include <map>
#include <thread>
#include <string>
#include <cstring>

#include <brynet/net/SocketLibFunction.h>
#include <brynet/net/fdset.h>
#include <brynet/utils/stack.h>

#include <brynet/net/Connector.h>

Expand All @@ -22,16 +18,16 @@ namespace brynet
class AsyncConnectAddr
{
public:
AsyncConnectAddr(const std::string& ip,
AsyncConnectAddr(std::string ip,
int port,
std::chrono::nanoseconds timeout,
const AsyncConnector::COMPLETED_CALLBACK& successCB,
const AsyncConnector::FAILED_CALLBACK& failedCB) :
mIP(ip),
AsyncConnector::COMPLETED_CALLBACK successCB,
AsyncConnector::FAILED_CALLBACK failedCB) :
mIP(std::move(ip)),
mPort(port),
mTimeout(timeout),
mSuccessCB(successCB),
mFailedCB(failedCB)
mSuccessCB(std::move(successCB)),
mFailedCB(std::move(failedCB))
{
}

Expand Down Expand Up @@ -61,11 +57,11 @@ namespace brynet
}

private:
std::string mIP;
int mPort;
std::chrono::nanoseconds mTimeout;
AsyncConnector::COMPLETED_CALLBACK mSuccessCB;
AsyncConnector::FAILED_CALLBACK mFailedCB;
const std::string mIP;
const int mPort;
const std::chrono::nanoseconds mTimeout;
const AsyncConnector::COMPLETED_CALLBACK mSuccessCB;
const AsyncConnector::FAILED_CALLBACK mFailedCB;
};

class ConnectorWorkInfo final : public NonCopyable
Expand Down
7 changes: 2 additions & 5 deletions src/brynet/net/Connector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_CONNECTOR_H_
#define BRYNET_NET_CONNECTOR_H_
#pragma once

#include <functional>
#include <memory>
Expand Down Expand Up @@ -58,6 +57,4 @@ namespace brynet
std::shared_ptr<bool> mIsRun;
};
}
}

#endif
}
5 changes: 1 addition & 4 deletions src/brynet/net/CurrentThread.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_CURRENTTHREAD_H_
#define BRYNET_NET_CURRENTTHREAD_H_
#pragma once

#include <thread>
#include <brynet/net/Platform.h>
Expand Down Expand Up @@ -29,5 +28,3 @@ namespace brynet
}
}
}

#endif
26 changes: 14 additions & 12 deletions src/brynet/net/DataSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DataSocket::DataSocket(TcpSocket::PTR socket,
#endif
mIP(socket->GetIP()),
mSocket(std::move(socket)),
mEventLoop(eventLoop),
mEventLoop(std::move(eventLoop)),
mAlreadyClose(false),
mMaxRecvBufferSize(maxRecvBufferSize)
{
Expand All @@ -42,7 +42,7 @@ DataSocket::DataSocket(TcpSocket::PTR socket,
mSSL = nullptr;
mIsHandsharked = false;
#endif
mEnterCallback = enterCallback;
mEnterCallback = std::move(enterCallback);
}

DataSocket::~DataSocket() BRYNET_NOEXCEPT
Expand Down Expand Up @@ -81,10 +81,14 @@ DataSocket::PTR DataSocket::Create(TcpSocket::PTR socket,
ENTER_CALLBACK enterCallback,
EventLoop::PTR eventLoop)
:
DataSocket(std::move(socket), maxRecvBufferSize, enterCallback, eventLoop)
DataSocket(std::move(socket), maxRecvBufferSize, std::move(enterCallback), std::move(eventLoop))
{}
};
return std::make_shared<make_shared_enabler>(std::move(socket), maxRecvBufferSize, enterCallback, eventLoop);
return std::make_shared<make_shared_enabler>(
std::move(socket),
maxRecvBufferSize,
std::move(enterCallback),
std::move(eventLoop));
}

bool DataSocket::onEnterEventLoop()
Expand Down Expand Up @@ -488,14 +492,12 @@ void DataSocket::quickFlush()
{
int num = 0;
size_t ready_send_len = 0;
for (PACKET_LIST_TYPE::iterator it = mSendList.begin(); it != mSendList.end();)
for(const auto& p : mSendList)
{
pending_packet& b = *it;
iov[num].iov_base = (void*)(b.data->c_str() + (b.data->size() - b.left));
iov[num].iov_len = b.left;
ready_send_len += b.left;
iov[num].iov_base = (void*)(p.data->c_str() + (p.data->size() - p.left));
iov[num].iov_len = p.left;
ready_send_len += p.left;

++it;
num++;
if (num >= MAX_IOVEC)
{
Expand Down Expand Up @@ -524,7 +526,7 @@ void DataSocket::quickFlush()
}

auto tmp_len = static_cast<size_t>(send_len);
for (PACKET_LIST_TYPE::iterator it = mSendList.begin(); it != mSendList.end();)
for (auto it = mSendList.begin(); it != mSendList.end();)
{
pending_packet& b = *it;
if (b.left > tmp_len)
Expand Down Expand Up @@ -582,7 +584,7 @@ void DataSocket::procCloseInLoop()
onClose();
}
#else
struct epoll_event ev = { 0, { 0 } };
struct epoll_event ev = { 0, { nullptr } };
epoll_ctl(mEventLoop->getEpollHandle(), EPOLL_CTL_DEL, mSocket->getFD(), &ev);
onClose();
#endif
Expand Down
7 changes: 2 additions & 5 deletions src/brynet/net/DataSocket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_DATASOCKET_H_
#define BRYNET_NET_DATASOCKET_H_
#pragma once

#include <memory>
#include <functional>
Expand Down Expand Up @@ -166,6 +165,4 @@ namespace brynet
Timer::WeakPtr mTimer;
};
}
}

#endif
}
7 changes: 2 additions & 5 deletions src/brynet/net/EventLoop.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_EVENTLOOP_H_
#define BRYNET_NET_EVENTLOOP_H_
#pragma once

#include <cstdint>
#include <functional>
Expand Down Expand Up @@ -115,6 +114,4 @@ namespace brynet
friend class DataSocket;
};
}
}

#endif
}
5 changes: 1 addition & 4 deletions src/brynet/net/ListenThread.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_TCP_ACCEPTOR_H_
#define BRYNET_NET_TCP_ACCEPTOR_H_
#pragma once

#include <string>
#include <functional>
Expand Down Expand Up @@ -44,5 +43,3 @@ namespace brynet
};
}
}

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/Noexcept.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _BRYNET_NET_NOEXCEPT_H
#define _BRYNET_NET_NOEXCEPT_H
#pragma once

#include <brynet/utils/CPP_VERSION.h>

Expand All @@ -8,5 +7,3 @@
#else
#define BRYNET_NOEXCEPT
#endif

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/Platform.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _PLATFORM_H
#define _PLATFORM_H
#pragma once

#if defined _MSC_VER || defined __MINGW32__
#define PLATFORM_WINDOWS
#else
#define PLATFORM_LINUX
#endif

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/PromiseReceive.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _BRYNET_NET_PROMISE_RECEIVE_H
#define _BRYNET_NET_PROMISE_RECEIVE_H
#pragma once

#include <brynet/net/TCPService.h>

Expand Down Expand Up @@ -161,5 +160,3 @@ namespace brynet
}
}
}

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/SSLHelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_SSL_HELPER_H_
#define BRYNET_NET_SSL_HELPER_H_
#pragma once

#include <string>
#include <memory>
Expand Down Expand Up @@ -48,5 +47,3 @@ namespace brynet
};
}
}

#endif
9 changes: 3 additions & 6 deletions src/brynet/net/Socket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_SOCKET_H_
#define BRYNET_NET_SOCKET_H_
#pragma once

#include <memory>
#include <string>
Expand Down Expand Up @@ -59,7 +58,7 @@ namespace brynet
class AcceptError : public std::runtime_error
{
public:
AcceptError(int errorCode)
explicit AcceptError(int errorCode)
:
std::runtime_error(std::to_string(errorCode)),
mErrorCode(errorCode)
Expand Down Expand Up @@ -103,6 +102,4 @@ namespace brynet
friend class DataSocket;
};
}
}

#endif
}
5 changes: 1 addition & 4 deletions src/brynet/net/SocketLibFunction.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_SOCKETLIBFUNCTION_H_
#define BRYNET_NET_SOCKETLIBFUNCTION_H_
#pragma once

#include <cstdbool>
#include <string>
Expand Down Expand Up @@ -29,5 +28,3 @@ namespace brynet
}
}
}

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/SocketLibTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef DODO_NET_SOCKETLIBTYPES_H_
#define DODO_NET_SOCKETLIBTYPES_H_
#pragma once

#include <brynet/net/Platform.h>

Expand Down Expand Up @@ -53,5 +52,3 @@ typedef int sock;
typedef unsigned short int port;
typedef unsigned long int ipaddress;
#define IP_SIZE (20)

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/SyncConnector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_SYNC_CONNECT_H_
#define BRYNET_NET_SYNC_CONNECT_H_
#pragma once

#include <chrono>
#include <string>
Expand All @@ -25,5 +24,3 @@ namespace brynet
brynet::net::AsyncConnector::PTR asyncConnector = nullptr);
}
}

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/TCPService.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef BRYNET_NET_TCP_SERVICE_H_
#define BRYNET_NET_TCP_SERVICE_H_
#pragma once

#include <vector>
#include <string>
Expand Down Expand Up @@ -75,5 +74,3 @@ namespace brynet
};
}
}

#endif
5 changes: 1 addition & 4 deletions src/brynet/net/fdset.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _BRYNET_NET_FDSET_INCLUDED_H
#define _BRYNET_NET_FDSET_INCLUDED_H
#pragma once

#include <stdbool.h>
#include <brynet/net/SocketLibTypes.h>
Expand Down Expand Up @@ -30,5 +29,3 @@ bool ox_fdset_check(struct fdset_s* self, sock fd, enum CheckType type);
#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 1ed5d98

Please sign in to comment.