Skip to content

Commit

Permalink
dgram, feat: method send return data size.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jan 13, 2018
1 parent 469d0d0 commit b9d53e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions fibjs/include/DgramSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class DgramSocket : public DgramSocket_base {
// DgramSocket_base
virtual result_t bind(int32_t port, exlib::string addr, AsyncEvent* ac);
virtual result_t bind(v8::Local<v8::Object> opts, AsyncEvent* ac);
virtual result_t send(Buffer_base* msg, int32_t port, exlib::string address, AsyncEvent* ac);
virtual result_t send(Buffer_base* msg, int32_t offset, int32_t length, int32_t port, exlib::string address, AsyncEvent* ac);
virtual result_t send(Buffer_base* msg, int32_t port, exlib::string address, int32_t& retVal, AsyncEvent* ac);
virtual result_t send(Buffer_base* msg, int32_t offset, int32_t length, int32_t port, exlib::string address, int32_t& retVal, AsyncEvent* ac);
virtual result_t address(obj_ptr<NObject>& retVal);
virtual result_t close();
virtual result_t close(v8::Local<v8::Function> callback);
Expand Down
16 changes: 9 additions & 7 deletions fibjs/include/ifs/DgramSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class DgramSocket_base : public EventEmitter_base {
// DgramSocket_base
virtual result_t bind(int32_t port, exlib::string addr, AsyncEvent* ac) = 0;
virtual result_t bind(v8::Local<v8::Object> opts, AsyncEvent* ac) = 0;
virtual result_t send(Buffer_base* msg, int32_t port, exlib::string address, AsyncEvent* ac) = 0;
virtual result_t send(Buffer_base* msg, int32_t offset, int32_t length, int32_t port, exlib::string address, AsyncEvent* ac) = 0;
virtual result_t send(Buffer_base* msg, int32_t port, exlib::string address, int32_t& retVal, AsyncEvent* ac) = 0;
virtual result_t send(Buffer_base* msg, int32_t offset, int32_t length, int32_t port, exlib::string address, int32_t& retVal, AsyncEvent* ac) = 0;
virtual result_t address(obj_ptr<NObject>& retVal) = 0;
virtual result_t close() = 0;
virtual result_t close(v8::Local<v8::Function> callback) = 0;
Expand Down Expand Up @@ -65,8 +65,8 @@ class DgramSocket_base : public EventEmitter_base {
public:
ASYNC_MEMBER2(DgramSocket_base, bind, int32_t, exlib::string);
ASYNC_MEMBER1(DgramSocket_base, bind, v8::Local<v8::Object>);
ASYNC_MEMBER3(DgramSocket_base, send, Buffer_base*, int32_t, exlib::string);
ASYNC_MEMBER5(DgramSocket_base, send, Buffer_base*, int32_t, int32_t, int32_t, exlib::string);
ASYNC_MEMBERVALUE4(DgramSocket_base, send, Buffer_base*, int32_t, exlib::string, int32_t);
ASYNC_MEMBERVALUE6(DgramSocket_base, send, Buffer_base*, int32_t, int32_t, int32_t, exlib::string, int32_t);
};
}

Expand Down Expand Up @@ -132,6 +132,8 @@ inline void DgramSocket_base::s_bind(const v8::FunctionCallbackInfo<v8::Value>&

inline void DgramSocket_base::s_send(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;

METHOD_NAME("DgramSocket.send");
METHOD_INSTANCE(DgramSocket_base);
METHOD_ENTER();
Expand All @@ -146,7 +148,7 @@ inline void DgramSocket_base::s_send(const v8::FunctionCallbackInfo<v8::Value>&
pInst->acb_send(v0, v1, v2, cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_send(v0, v1, v2);
hr = pInst->ac_send(v0, v1, v2, vr);

ASYNC_METHOD_OVER(5, 4);

Expand All @@ -160,9 +162,9 @@ inline void DgramSocket_base::s_send(const v8::FunctionCallbackInfo<v8::Value>&
pInst->acb_send(v0, v1, v2, v3, v4, cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_send(v0, v1, v2, v3, v4);
hr = pInst->ac_send(v0, v1, v2, v3, v4, vr);

METHOD_VOID();
METHOD_RETURN();
}

inline void DgramSocket_base::s_address(const v8::FunctionCallbackInfo<v8::Value>& args)
Expand Down
9 changes: 6 additions & 3 deletions fibjs/src/net/DgramSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ result_t DgramSocket::bind(v8::Local<v8::Object> opts, AsyncEvent* ac)
return bind(port, addr, ac);
}

result_t DgramSocket::send(Buffer_base* msg, int32_t port, exlib::string address, AsyncEvent* ac)
result_t DgramSocket::send(Buffer_base* msg, int32_t port, exlib::string address,
int32_t& retVal, AsyncEvent* ac)
{
if (m_closed)
return CHECK_ERROR(CALL_E_INVALID_CALL);
Expand Down Expand Up @@ -305,11 +306,13 @@ result_t DgramSocket::send(Buffer_base* msg, int32_t port, exlib::string address
== SOCKET_ERROR)
return CHECK_ERROR(SocketError());

retVal = (int32_t)strData.length();

return 0;
}

result_t DgramSocket::send(Buffer_base* msg, int32_t offset, int32_t length, int32_t port,
exlib::string address, AsyncEvent* ac)
exlib::string address, int32_t& retVal, AsyncEvent* ac)
{
if (offset < 0 || length <= 0)
return CHECK_ERROR(CALL_E_INVALIDARG);
Expand All @@ -320,7 +323,7 @@ result_t DgramSocket::send(Buffer_base* msg, int32_t offset, int32_t length, int
obj_ptr<Buffer_base> msg1;
msg->slice(offset, offset + length, msg1);

return send(msg1, port, address, ac);
return send(msg1, port, address, retVal, ac);
}

result_t DgramSocket::address(obj_ptr<NObject>& retVal)
Expand Down
6 changes: 4 additions & 2 deletions idl/zh-cn/DgramSocket.idl
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ interface DgramSocket : EventEmitter
@param msg 指定发送的数据
@param port 指定发送的目的端口
@param address 指定发送的目的地址
@return 返回发送尺寸
*/
send(Buffer msg, Integer port, String address = "") async;
Integer send(Buffer msg, Integer port, String address = "") async;

/*! @brief 在 socket 上发送一个数据包
@param msg 指定发送的数据
@param offset 从指定偏移开始发送
@param length 之发送指定长度
@param port 指定发送的目的端口
@param address 指定发送的目的地址
@return 返回发送尺寸
*/
send(Buffer msg, Integer offset, Integer length, Integer port, String address = "") async;
Integer send(Buffer msg, Integer offset, Integer length, Integer port, String address = "") async;

/*! @brief 返回一个包含 socket 地址信息的对象。对于 UDP socket,该对象将包含 address、family 和 port 属性。
@return 返回对象绑定地址
Expand Down

0 comments on commit b9d53e2

Please sign in to comment.