..

Committer:
ImranBilalButt
Date:
Fri Aug 23 13:29:35 2019 +0000
Revision:
0:5f745af3ec9b
Child:
1:a6995e66c9f7
..

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ImranBilalButt 0:5f745af3ec9b 1 /*
ImranBilalButt 0:5f745af3ec9b 2 * PackageLicenseDeclared: Apache-2.0
ImranBilalButt 0:5f745af3ec9b 3 * Copyright (c) 2017 ARM Limited
ImranBilalButt 0:5f745af3ec9b 4 *
ImranBilalButt 0:5f745af3ec9b 5 * Licensed under the Apache License, Version 2.0 (the "License");
ImranBilalButt 0:5f745af3ec9b 6 * you may not use this file except in compliance with the License.
ImranBilalButt 0:5f745af3ec9b 7 * You may obtain a copy of the License at
ImranBilalButt 0:5f745af3ec9b 8 *
ImranBilalButt 0:5f745af3ec9b 9 * http://www.apache.org/licenses/LICENSE-2.0
ImranBilalButt 0:5f745af3ec9b 10 *
ImranBilalButt 0:5f745af3ec9b 11 * Unless required by applicable law or agreed to in writing, software
ImranBilalButt 0:5f745af3ec9b 12 * distributed under the License is distributed on an "AS IS" BASIS,
ImranBilalButt 0:5f745af3ec9b 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ImranBilalButt 0:5f745af3ec9b 14 * See the License for the specific language governing permissions and
ImranBilalButt 0:5f745af3ec9b 15 * limitations under the License.
ImranBilalButt 0:5f745af3ec9b 16 */
ImranBilalButt 0:5f745af3ec9b 17
ImranBilalButt 0:5f745af3ec9b 18 #include "TLSSocket.h"
ImranBilalButt 0:5f745af3ec9b 19
ImranBilalButt 0:5f745af3ec9b 20 #define TRACE_GROUP "TLSS"
ImranBilalButt 0:5f745af3ec9b 21 #include "mbed-trace/mbed_trace.h"
ImranBilalButt 0:5f745af3ec9b 22
ImranBilalButt 0:5f745af3ec9b 23
ImranBilalButt 0:5f745af3ec9b 24 /*TLSSocket::SocketAddress getsock() {
ImranBilalButt 0:5f745af3ec9b 25 return sock_addr;
ImranBilalButt 0:5f745af3ec9b 26 }*/
ImranBilalButt 0:5f745af3ec9b 27
ImranBilalButt 0:5f745af3ec9b 28
ImranBilalButt 0:5f745af3ec9b 29 nsapi_error_t TLSSocket::connect(const char *host, uint16_t port)
ImranBilalButt 0:5f745af3ec9b 30 {
ImranBilalButt 0:5f745af3ec9b 31 printf("[.] Hello from TLSSocket::connect() \n");
ImranBilalButt 0:5f745af3ec9b 32 int ret;
ImranBilalButt 0:5f745af3ec9b 33
ImranBilalButt 0:5f745af3ec9b 34 sock_addr.set_ip_address(host);
ImranBilalButt 0:5f745af3ec9b 35 sock_addr.set_port(port);
ImranBilalButt 0:5f745af3ec9b 36 set_hostname(host);
ImranBilalButt 0:5f745af3ec9b 37
ImranBilalButt 0:5f745af3ec9b 38 uint32_t init, final, TCPH, TTPH;
ImranBilalButt 0:5f745af3ec9b 39 init = osKernelGetTickCount();
ImranBilalButt 0:5f745af3ec9b 40 /* Send a 'Client Hello' buffer in order to start a thread on the server */
ImranBilalButt 0:5f745af3ec9b 41 const char* buffer = "Client Hello";
ImranBilalButt 0:5f745af3ec9b 42 if ((ret = udp_socket.sendto(host, port, (const char*) buffer, strlen(buffer))) <= 0)
ImranBilalButt 0:5f745af3ec9b 43 printf("Couldn't send 'Client Hello' \n");
ImranBilalButt 0:5f745af3ec9b 44 else
ImranBilalButt 0:5f745af3ec9b 45 printf("sent 'Client Hello' \n");
ImranBilalButt 0:5f745af3ec9b 46 wait(1);
ImranBilalButt 0:5f745af3ec9b 47 final = osKernelGetTickCount();
ImranBilalButt 0:5f745af3ec9b 48
ImranBilalButt 0:5f745af3ec9b 49 TCPH = final - init;
ImranBilalButt 0:5f745af3ec9b 50 TTPH = TCPH/osKernelGetTickFreq();
ImranBilalButt 0:5f745af3ec9b 51
ImranBilalButt 0:5f745af3ec9b 52 printf("\nTCPH: %d\n", TCPH);
ImranBilalButt 0:5f745af3ec9b 53 printf("\nTTPH: %d\n", TTPH);
ImranBilalButt 0:5f745af3ec9b 54 printf("\nTickFreq: %d\n", osKernelGetTickFreq());
ImranBilalButt 0:5f745af3ec9b 55
ImranBilalButt 0:5f745af3ec9b 56 return TLSSocketWrapper::connect(sock_addr);
ImranBilalButt 0:5f745af3ec9b 57 }