[udp6] update UDP socket definitions (#5231)

This commit updates the  public OT `otUdp{}` (like `otUdpConnect`, or
`otUpdSend()`) functions to requires a pointer the OpenThread instance
to be passed as their first parameter (this harmonizes the definitions
with other public APIs and removes the need for `otUdpSocket` to track
the instance).

The core implementation in `udp6` module is updated to define
`SocketHandle` as an internal mirror of `otUdpSocket` structure. The
socket related methods `Open`(), `Bind()`, `Connect()`, etc., are
moved to `Udp` class itself (with a `SocketHandle` passed as a
parameter). For core internal use `Socket` class is defined as a
sub-class of `SocketHandle` and `InstanceLocator` providing same
helper methods. The separation between `SocketHandle` and `Socket`
type addresses the problem that can be caused by the treating/casting
publicly provided `otUdpSockt` objects as `InstanceLocator`.
This commit is contained in:
Abtin Keshavarzian
2020-07-14 10:03:03 -07:00
committed by GitHub
parent 9c660f6425
commit dc1d47d2c0
14 changed files with 408 additions and 349 deletions
+4 -4
View File
@@ -86,7 +86,7 @@ otError UdpExample::ProcessBind(uint8_t aArgsLength, char *aArgs[])
sockaddr.mPort = static_cast<uint16_t>(value);
error = otUdpBind(&mSocket, &sockaddr);
error = otUdpBind(mInterpreter.mInstance, &mSocket, &sockaddr);
exit:
return error;
@@ -110,7 +110,7 @@ otError UdpExample::ProcessConnect(uint8_t aArgsLength, char *aArgs[])
sockaddr.mPort = static_cast<uint16_t>(value);
error = otUdpConnect(&mSocket, &sockaddr);
error = otUdpConnect(mInterpreter.mInstance, &mSocket, &sockaddr);
exit:
return error;
@@ -121,7 +121,7 @@ otError UdpExample::ProcessClose(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
return otUdpClose(&mSocket);
return otUdpClose(mInterpreter.mInstance, &mSocket);
}
otError UdpExample::ProcessOpen(uint8_t aArgsLength, char *aArgs[])
@@ -218,7 +218,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
}
}
error = otUdpSend(&mSocket, message, &messageInfo);
error = otUdpSend(mInterpreter.mInstance, &mSocket, message, &messageInfo);
exit: