Permalink
Browse files

core, refactor: add trace_tcp option.

  • Loading branch information...
xicilion committed Nov 1, 2017
1 parent 0fe6b96 commit f4be9559eb46e21877d99a541c224e8cc42cf5f0
Showing with 47 additions and 0 deletions.
  1. +2 −0 fibjs/include/options.h
  2. +2 −0 fibjs/src/base/options.cpp
  3. +21 −0 fibjs/src/io/AsyncIO_ev.cpp
  4. +22 −0 fibjs/src/io/AsyncIO_iocp.cpp
View
@@ -18,6 +18,8 @@ extern bool g_prof;
extern int32_t g_prof_interval;
extern bool g_cov;
extern bool g_tracetcp;
}
#endif
@@ -26,6 +26,8 @@ int32_t g_prof_interval = 1000;
bool g_cov = false;
bool g_tracetcp = false;
#ifdef DEBUG
#define GUARD_SIZE 32
#else
@@ -12,13 +12,29 @@
#include "AsyncIO.h"
#include "Socket.h"
#include "ifs/net.h"
#include "ifs/console.h"
#include "Buffer.h"
#include <ev/ev.h>
#include <fcntl.h>
#include <exlib/include/thread.h>
#include "options.h"
namespace fibjs {
exlib::string clean_string(exlib::string s)
{
exlib::string s1(s);
char* c_buf = s1.c_buffer();
int32_t len = (int32_t)s1.length();
for (int32_t i = 0; i < len; i++)
if ((c_buf[i] < 32 && c_buf[i] != 0xd && c_buf[i] != 0xa) || c_buf[i] > 127)
c_buf[i] = '.';
return s1;
}
void setOption(intptr_t& s)
{
int32_t keepAlive = 1;
@@ -498,6 +514,8 @@ result_t AsyncIO::read(int32_t bytes, obj_ptr<Buffer_base>& retVal,
m_buf.resize(m_pos);
m_retVal = new Buffer(m_buf);
if (g_tracetcp)
outLog(console_base::_NOTICE, clean_string(m_buf));
return 0;
}
@@ -550,6 +568,9 @@ result_t AsyncIO::write(Buffer_base* data, AsyncEvent* ac)
data->toString(m_buf);
m_p = m_buf.c_str();
m_sz = m_buf.length();
if (g_tracetcp)
outLog(console_base::_WARN, clean_string(m_buf));
}
virtual result_t process()
@@ -11,14 +11,30 @@
#include "utils.h"
#include "Socket.h"
#include "ifs/net.h"
#include "ifs/console.h"
#include "Buffer.h"
#include <fcntl.h>
#include <mswsock.h>
#include <mstcpip.h>
#include <exlib/include/thread.h>
#include "options.h"
namespace fibjs {
exlib::string clean_string(exlib::string s)
{
exlib::string s1(s);
char* c_buf = s1.c_buffer();
int32_t len = (int32_t)s1.length();
for (int32_t i = 0; i < len; i++)
if ((c_buf[i] < 32 && c_buf[i] != 0xd && c_buf[i] != 0xa) || c_buf[i] > 127)
c_buf[i] = '.';
return s1;
}
void setOption(SOCKET s)
{
int32_t keepAlive = 1;
@@ -394,6 +410,9 @@ result_t AsyncIO::read(int32_t bytes, obj_ptr<Buffer_base>& retVal,
if (m_pos) {
m_buf.resize(m_pos);
m_retVal = new Buffer(m_buf);
if (g_tracetcp)
outLog(console_base::_NOTICE, clean_string(m_buf));
} else
nError = CALL_RETURN_NULL;
}
@@ -432,6 +451,9 @@ result_t AsyncIO::write(Buffer_base* data, AsyncEvent* ac)
data->toString(m_buf);
m_p = m_buf.c_str();
m_sz = (int32_t)m_buf.length();
if (g_tracetcp)
outLog(console_base::_WARN, clean_string(m_buf));
}
virtual result_t process()

0 comments on commit f4be955

Please sign in to comment.