I am in the process of modifying the TCP Server example found on the mbed site into a telnet server to provide remote interactive access to my application. The code modification went well and works with a few dummy commands as placeholders. When I compile this code I receive the warning message shown below:
Description Resource Location
---------------------------------------------------------------------------------
transfer of control bypasses initialization of: 10_telnet.c Line: 142, Col: 15
This telnet code seems to work OK with what little testing I've done, but I am concerned by this message that "onListening TCPSocketEvent()" may at sometime be called before it is initialized. I think I am initializing, binding the port, and checking for errors properly as in "TEL_init()" below. I have initialized "EthernetNetIf eth;" in an earlier routine to get an IP address.
What is spooking the compiler? Should I be concerned about this warning being a latent bug sometime in the future?
141: void onListeningTCPSocketEvent(TCPSocketEvent e)
142: switch (e) {
//*****************************************************************************
// Telnet Server
//*****************************************************************************
#include "mbed.h"
#include "EthernetNetIf.h"
#include "TCPSocket.h"
extern DigitalOut led4;
extern EthernetNetIf eth;
TCPSocket ListeningSock;
TCPSocket* pConnectedSock; // for ConnectedSock
Host client;
TCPSocketErr err;
Timer tel_tmr;
#define TELNET_LISTENING_PORT 12345
void onConnectedTCPSocketEvent(TCPSocketEvent e);
void onListeningTCPSocketEvent(TCPSocketEvent e);
//---------------------------------------------------------------------------------------
// TEL_init - Initialize telenet port
//---------------------------------------------------------------------------------------
int TEL_init(void)
{
printf("TEL: Initializing telnet port...\r\n");
IpAddr ip = eth.getIp();
ListeningSock.setOnEvent (&onListeningTCPSocketEvent); // Set the callbacks for Listening
err = ListeningSock.bind (Host(IpAddr(), TELNET_LISTENING_PORT)); // bind and listen on TCP
if (err) {
printf("TEL: Port binding error: %d\r\n", err); // Deal with that error...
}
else {
err=ListeningSock.listen(); // Start listening
if (err) {
printf("TEL: Listening Error: %d\r\n", err);
}
else {
printf("TEL: Now listening on: %d.%d.%d.%d:%d\r\n",
ip[0], ip[1], ip[2], ip[3], TELNET_LISTENING_PORT);
tel_tmr.start();
}
}
return(0);
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
void TEL_Poll (void)
{
Net::poll();
if (tel_tmr.read() > 0.2) { // sec
led4=!led4; //Show that we are alive
tel_tmr.reset();
}
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
void telnet_command_handler(char* telBfr, int len) {
printf("Received %c, length = %d\r\n", telBfr[0], len);
switch (telBfr[0])
{
case 'a':
strcpy (telBfr, "a: Hello from Telnet Server.\r\n");
break;
case 'b':
strcpy (telBfr, "b: Telnet Server.\r\n");
break;
case 'c':
strcpy (telBfr, "c: Telnet Server.\r\n");
break;
case 'd':
strcpy (telBfr, "d: Good Bye!\r\n");
break;
default:
strcpy (telBfr, "?\r\n");
break;
}
len = strlen(telBfr);
pConnectedSock->send(telBfr, len);
printf("Send len = %d\r\n", len);
printf("Received&Wrote:%s\r\n",telBfr);
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
void onConnectedTCPSocketEvent(TCPSocketEvent e) {
switch (e)
{
case TCPSOCKET_CONNECTED:
printf("TCP Socket Connected\r\n");
break;
case TCPSOCKET_WRITEABLE:
//Can now write some data...
printf("TCP Socket Writable\r\n");
break;
case TCPSOCKET_READABLE:
//Can now read dome data...
printf("TCP Socket Readable\r\n");
// Read in any available data into the buffer
char buff[128];
while ( int len = pConnectedSock->recv(buff, 128) ) {
telnet_command_handler(buff, len);
}
break;
case TCPSOCKET_CONTIMEOUT:
printf("TCP Socket Timeout\r\n");
break;
case TCPSOCKET_CONRST:
printf("TCP Socket CONRST\r\n");
break;
case TCPSOCKET_CONABRT:
printf("TCP Socket CONABRT\r\n");
break;
case TCPSOCKET_ERROR:
printf("TCP Socket Error\r\n");
break;
case TCPSOCKET_DISCONNECTED:
//Close socket...
printf("TCP Socket Disconnected\r\n");
pConnectedSock->close();
break;
default:
printf("DEFAULT\r\n");
}
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
void onListeningTCPSocketEvent(TCPSocketEvent e) {
switch (e) {
case TCPSOCKET_ACCEPT:
printf("Listening: TCP Socket Accepted\r\n");
// Accepts connection from client and gets connected socket.
err=ListeningSock.accept(&client, &pConnectedSock);
if (err) {
printf("onListeningTcpSocketEvent : Could not accept connection.\r\n");
return; //Error in accept, discard connection
}
// Setup the new socket events
pConnectedSock->setOnEvent(&onConnectedTCPSocketEvent);
// We can find out from where the connection is coming by looking at the
// Host parameter of the accept() method
IpAddr clientIp = client.getIp();
printf("Listening: Incoming TCP connection from %d.%d.%d.%d\r\n",
clientIp[0], clientIp[1], clientIp[2], clientIp[3]);
break;
// the following cases will not happen
case TCPSOCKET_CONNECTED:
printf("Listening: TCP Socket Connected\r\n");
break;
case TCPSOCKET_WRITEABLE:
printf("Listening: TCP Socket Writable\r\n");
break;
case TCPSOCKET_READABLE:
printf("Listening: TCP Socket Readable\r\n");
break;
case TCPSOCKET_CONTIMEOUT:
printf("Listening: TCP Socket Timeout\r\n");
break;
case TCPSOCKET_CONRST:
printf("Listening: TCP Socket CONRST\r\n");
break;
case TCPSOCKET_CONABRT:
printf("Listening: TCP Socket CONABRT\r\n");
break;
case TCPSOCKET_ERROR:
printf("Listening: TCP Socket Error\r\n");
break;
case TCPSOCKET_DISCONNECTED:
//Close socket...
printf("TEL: Listening port %d disconnected\r\n", TELNET_LISTENING_PORT);
ListeningSock.close();
break;
default:
printf("DEFAULT\r\n");
}
}
I am in the process of modifying the TCP Server example found on the mbed site into a telnet server to provide remote interactive access to my application. The code modification went well and works with a few dummy commands as placeholders. When I compile this code I receive the warning message shown below:
This telnet code seems to work OK with what little testing I've done, but I am concerned by this message that "onListening TCPSocketEvent()" may at sometime be called before it is initialized. I think I am initializing, binding the port, and checking for errors properly as in "TEL_init()" below. I have initialized "EthernetNetIf eth;" in an earlier routine to get an IP address.
What is spooking the compiler? Should I be concerned about this warning being a latent bug sometime in the future?