| 1 |
// Copyright (c) Microsoft. All rights reserved. |
| 2 |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
#include "mbed.h" |
| 5 |
|
| 6 |
#include <stddef.h> |
| 7 |
#include "TCPSocketConnection.h" |
| 8 |
#include "azure_c_shared_utility/tcpsocketconnection_c.h" |
| 9 |
|
| 10 |
|
| 11 |
TCPSOCKETCONNECTION_HANDLE tcpsocketconnection_create(void) |
| 12 |
{ |
| 13 |
return new TCPSocketConnection(); |
| 14 |
} |
| 15 |
|
| 16 |
void tcpsocketconnection_set_blocking(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, bool blocking, unsigned int timeout) |
| 17 |
{ |
| 18 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 19 |
tsc->set_blocking(blocking, timeout); |
| 20 |
} |
| 21 |
|
| 22 |
void tcpsocketconnection_destroy(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle) |
| 23 |
{ |
| 24 |
delete (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 25 |
} |
| 26 |
|
| 27 |
int tcpsocketconnection_connect(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, const char* host, const int port) |
| 28 |
{ |
| 29 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 30 |
return tsc->connect(host, port); |
| 31 |
} |
| 32 |
|
| 33 |
bool tcpsocketconnection_is_connected(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle) |
| 34 |
{ |
| 35 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 36 |
return tsc->is_connected(); |
| 37 |
} |
| 38 |
|
| 39 |
void tcpsocketconnection_close(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle) |
| 40 |
{ |
| 41 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 42 |
tsc->close(); |
| 43 |
} |
| 44 |
|
| 45 |
int tcpsocketconnection_send(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, const char* data, int length) |
| 46 |
{ |
| 47 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 48 |
return tsc->send((char*)data, length); |
| 49 |
} |
| 50 |
|
| 51 |
int tcpsocketconnection_send_all(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, const char* data, int length) |
| 52 |
{ |
| 53 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 54 |
return tsc->send_all((char*)data, length); |
| 55 |
} |
| 56 |
|
| 57 |
int tcpsocketconnection_receive(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, char* data, int length) |
| 58 |
{ |
| 59 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 60 |
return tsc->receive(data, length); |
| 61 |
} |
| 62 |
|
| 63 |
int tcpsocketconnection_receive_all(TCPSOCKETCONNECTION_HANDLE tcpSocketConnectionHandle, char* data, int length) |
| 64 |
{ |
| 65 |
TCPSocketConnection* tsc = (TCPSocketConnection*)tcpSocketConnectionHandle; |
| 66 |
return tsc->receive_all(data, length); |
| 67 |
} |