5 changed files with 236 additions and 70 deletions
-
78i_xsync_udp.hpp
-
2iflytop_xsync_protocol
-
81xsync.cpp
-
122xsync.hpp
-
23xsync_errcode.hpp
@ -0,0 +1,78 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <functional>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "xsync_errcode.hpp"
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
class XsyncNetAdd { |
|||
public: |
|||
XsyncNetAdd(){}; |
|||
XsyncNetAdd(string ip, uint32_t port) : ip(ip), port(port) {} |
|||
string ip; |
|||
uint32_t port; |
|||
}; |
|||
|
|||
class I_XSUDP { |
|||
public: |
|||
typedef function<void(XsyncNetAdd& from, uint8_t* data, size_t length)> onMessage_t; |
|||
|
|||
public: |
|||
/**
|
|||
* @brief 初始化UDP |
|||
* |
|||
* @param ip localip default 0 |
|||
* @param localport localport |
|||
* @return int |
|||
*/ |
|||
virtual xs_error_code_t initialize(string ip, int localport) = 0; |
|||
/**
|
|||
* @brief 发送UDP消息 |
|||
* |
|||
* @param to |
|||
* @param data |
|||
* @param length |
|||
* @return int |
|||
* >0 发送成功,返回发送的字节数 |
|||
* <0 发送失败 |
|||
*/ |
|||
virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) = 0; |
|||
/**
|
|||
* @brief 接收UDP消息 |
|||
* |
|||
* @param data |
|||
* @param length |
|||
* @param from |
|||
* @return int |
|||
* >0 接收成功,返回接收的字节数 |
|||
* <0 接收失败 |
|||
*/ |
|||
virtual xs_error_code_t receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) = 0; |
|||
|
|||
/**
|
|||
* @brief 开始接收UDP消息 |
|||
* |
|||
* @param onMessage |
|||
* @return xs_error_code_t |
|||
*/ |
|||
virtual xs_error_code_t startReceive(onMessage_t onMessage) = 0; |
|||
virtual xs_error_code_t stopReceive() = 0; |
|||
|
|||
virtual ~I_XSUDP() {} |
|||
}; |
|||
|
|||
class I_XSUDPFactory { |
|||
public: |
|||
virtual shared_ptr<I_XSUDP> createXSUDP() = 0; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1 +1 @@ |
|||
Subproject commit dd0c38c767378dbe9010cd7e94bf1bf7cf0e40d5 |
|||
Subproject commit 3a13ffc983b65ba14947d88ea5a340d592f1fd22 |
@ -0,0 +1,23 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <functional>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
typedef enum { |
|||
kxs_ec_success = 0, |
|||
kxs_ec_overtime, |
|||
kxs_ec_socket_fail, |
|||
kxs_ec_bind_fail, |
|||
kxs_ec_send_fail, |
|||
kxs_ec_receive_fail, |
|||
kxs_ec_setsockopt_rx_timeout_fail, |
|||
} xs_error_code_t; |
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue