|
|
@ -217,7 +217,6 @@ void Wiz810MjDevice::setMac(byte b0, byte b1, byte b2, byte b3, byte b4, byte b5
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- NetworkConnection ---- */
|
|
|
|
/* ---- NetworkConnection ---- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Make this 'NetworkServerConnection'? Or just 'ServerConnection'?
|
|
|
|
// TODO: Make this 'NetworkServerConnection'? Or just 'ServerConnection'?
|
|
|
|
// TODO: Pull one-line methods into class definition to allow inlining?
|
|
|
|
// TODO: Pull one-line methods into class definition to allow inlining?
|
|
|
|
class NetworkConnection { // Essentially a Socket wrapper
|
|
|
|
class NetworkConnection { // Essentially a Socket wrapper
|
|
|
@ -283,6 +282,8 @@ void NetworkConnection::close() {
|
|
|
|
|
|
|
|
|
|
|
|
/* -- NetworkInterface -- */
|
|
|
|
/* -- NetworkInterface -- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define HANDLE_BAD_ERROR() while (1) {};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO?: Do we want to have a "default" socket accessible by 'Network.read()' etc?
|
|
|
|
// TODO?: Do we want to have a "default" socket accessible by 'Network.read()' etc?
|
|
|
|
class NetworkInterface {
|
|
|
|
class NetworkInterface {
|
|
|
|
|
|
|
|
|
|
|
@ -334,7 +335,15 @@ NetworkConnection NetworkInterface::listen(uint16_t port) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
NetworkConnection connection = NetworkConnection(port);
|
|
|
|
NetworkConnection connection = NetworkConnection(port);
|
|
|
|
|
|
|
|
|
|
|
|
connection.listen();
|
|
|
|
// TODO: How to best handle errors?
|
|
|
|
|
|
|
|
// There's two major categories I can think of currently:
|
|
|
|
|
|
|
|
// 1) A socket wasn't available to listen in the first place
|
|
|
|
|
|
|
|
// 2) The listen attempt failed for some reason
|
|
|
|
|
|
|
|
// Using 'HANDLE_BAD_ERROR()' (currently an infinite loop) is
|
|
|
|
|
|
|
|
// not ideal but should prevent the above errors slipping by unnoticed.
|
|
|
|
|
|
|
|
if (!connection.listen()) {
|
|
|
|
|
|
|
|
HANDLE_BAD_ERROR();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|