Skip to content

Commit

Permalink
mod code
Browse files Browse the repository at this point in the history
  • Loading branch information
fanchy committed Feb 6, 2019
1 parent 652e26a commit 492e3f9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
6 changes: 3 additions & 3 deletions fflib/net/msg_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MsgSender
{
if (pSocket)
{
if (0 == pSocket->get_sc()->get_type())
if (0 == pSocket->getSocketCtrl()->get_type())
{
MessageHead h(cmd_);
h.size = str_.size();
Expand Down Expand Up @@ -48,15 +48,15 @@ class MsgSender
{
if (pSocket)
{
if (0 == pSocket->get_sc()->get_type())
if (0 == pSocket->getSocketCtrl()->get_type())
{
std::string body = msg_.encode_data();
MessageHead h(cmd_);
h.size = body.size();
h.hton();
std::string dest((const char*)&h, sizeof(h));
dest += body;

pSocket->asyncSend(dest);
}
else
Expand Down
8 changes: 4 additions & 4 deletions fflib/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class SocketI: public Fd
virtual void open() = 0;
virtual void asyncSend(const std::string& buff_) = 0;
virtual void asyncRecv() = 0;
virtual void safeDelete() { delete this; }
virtual void safeDelete()= 0;
virtual void set_data(void* p) { m_data = p; }
template<typename T>
T* get_data() const { return (T*)m_data; }
virtual SocketCtrlI* get_sc() = 0;

virtual SocketCtrlI* getSocketCtrl() = 0;

virtual void sendRaw(const std::string& buff_) = 0;
private:
void* m_data;
Expand Down
6 changes: 3 additions & 3 deletions fflib/net/socketimpl/socket_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int SocketLinux::handleEpollRead_impl()

int SocketLinux::handleEpollDel()
{
m_tq->post(TaskBinder::gen(&SocketCtrlI::handleError, this->get_sc(), this));
m_tq->post(TaskBinder::gen(&SocketCtrlI::handleError, this->getSocketCtrl(), this));
return 0;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ void SocketLinux::send_impl(const string& buff_src, int flag)
{
return;
}

ff_str_buffer_t new_buff;
new_buff.buff = buff_;
new_buff.flag = flag;
Expand All @@ -178,7 +178,7 @@ void SocketLinux::send_impl(const string& buff_src, int flag)
m_send_buffer.push_back(new_buff);
return;
}

int ret = do_send(&new_buff);

if (ret < 0)
Expand Down
8 changes: 4 additions & 4 deletions fflib/net/socketimpl/socket_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SocketLinux: public SocketI
int has_send_size;
int flag;
std::string buff;

int left_size() const { return buff.size() - has_send_size; }
const char* cur_data() const { return buff.c_str() + has_send_size; }
void consume(int n) { has_send_size += n; }
Expand All @@ -48,7 +48,7 @@ class SocketLinux: public SocketI
virtual void asyncSend(const std::string& buff_);
virtual void asyncRecv();
virtual void safeDelete();

int handleEpollRead_impl();
int handleEpollWrite_impl();
int handle_epoll_error_impl();
Expand All @@ -57,8 +57,8 @@ class SocketLinux: public SocketI
void send_str_impl(const std::string& buff_);
void send_impl(const std::string& buff_, int flag = 0);
void close_impl();
SocketCtrlI* get_sc() { return m_sc; }

SocketCtrlI* getSocketCtrl() { return m_sc; }
private:
bool is_open() { return m_fd > 0; }

Expand Down
12 changes: 5 additions & 7 deletions fflib/net/socketimpl/socket_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int SocketWin::handleEpollRead_impl()
{
int nread = 0;
char recv_buffer[RECV_BUFFER_SIZE];

do
{
nread = ::read(m_fd, recv_buffer, sizeof(recv_buffer) - 1);
Expand Down Expand Up @@ -134,15 +134,15 @@ int SocketWin::handleEpollRead_impl()
return -1;
}
}

} while(1);
}
return 0;
}

int SocketWin::handleEpollDel()
{
m_tq->post(TaskBinder::gen(&SocketCtrlI::handleError, this->get_sc(), this));
m_tq->post(TaskBinder::gen(&SocketCtrlI::handleError, this->getSocketCtrl(), this));
return 0;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ void SocketWin::send_impl(const string& buff_src, int flag)
{
return;
}

ff_str_buffer_t new_buff;
new_buff.buff = buff_;
new_buff.flag = flag;
Expand All @@ -215,7 +215,7 @@ void SocketWin::send_impl(const string& buff_src, int flag)
m_send_buffer.push_back(new_buff);
return;
}

int ret = do_send(&new_buff);

if (ret < 0)
Expand Down Expand Up @@ -277,7 +277,6 @@ void SocketWin::asyncRecv()

void SocketWin::safeDelete()
{
//printf("SocketWin::safeDelete %p\n", this);
struct lambda_t
{
static void exe(void* p_)
Expand All @@ -288,4 +287,3 @@ void SocketWin::safeDelete()
m_tq->post(Task(&lambda_t::exe, this));
}
#endif

11 changes: 5 additions & 6 deletions fflib/net/socketimpl/socket_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SocketWin: public SocketI
int has_send_size;
int flag;
std::string buff;

int left_size() const { return buff.size() - has_send_size; }
const char* cur_data() const { return buff.c_str() + has_send_size; }
void consume(int n) { has_send_size += n; }
Expand All @@ -48,7 +48,7 @@ class SocketWin: public SocketI
virtual void asyncSend(const std::string& buff_);
virtual void asyncRecv();
virtual void safeDelete();

int handleEpollRead_impl();
int handleEpollWrite_impl();
int handle_epoll_error_impl();
Expand All @@ -57,9 +57,9 @@ class SocketWin: public SocketI
void send_str_impl(const std::string& buff_);
void send_impl(const std::string& buff_, int flag = 0);
void close_impl();
SocketCtrlI* get_sc() { return m_sc; }

SocketCtrlI* getSocketCtrl() { return m_sc; }

void post_recv_msg(const std::string& data);
private:
bool is_open() { return m_fd > 0; }
Expand All @@ -77,4 +77,3 @@ class SocketWin: public SocketI

#endif
#endif

0 comments on commit 492e3f9

Please sign in to comment.