14
14
*/
15
15
16
16
#include <errno.h>
17
+ #include <arpa/inet.h>
18
+ #include <unistd.h>
19
+ #include <string.h>
20
+ #include <stdbool.h>
17
21
18
22
#include "jerry-debugger.h"
19
23
#include "jerry-port.h"
@@ -42,56 +46,58 @@ bool remote_init ()
42
46
/* Create an endpoint for communication */
43
47
if ((sock = socket (AF_INET , SOCK_STREAM , 0 )) == -1 )
44
48
{
45
- jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Socket error! \n" );
49
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error: %s \n" , strerror ( errno ) );
46
50
return false;
47
51
}
48
52
49
53
/* Set the options on socket */
50
54
if (setsockopt (sock , SOL_SOCKET , SO_REUSEADDR , & optval , sizeof (int )) == -1 )
51
55
{
52
- jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Setsockopt error! \n" );
56
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Erorr: %s \n" , strerror ( errno ) );
53
57
return false;
54
58
}
55
59
56
60
/* Bind to the server address */
57
61
if (bind (sock , (struct sockaddr * )& server_addr , sizeof (struct sockaddr )) == -1 )
58
62
{
59
- jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Bind error, unable to bind! \n" );
63
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error: %s \n" , strerror ( errno ) );
60
64
return false;
61
65
}
62
66
63
67
/* Listen for connections on socket */
64
68
if (listen (sock , BACKLOG ) == -1 )
65
69
{
66
- jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Listen error! \n" );
70
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error: %s \n" , strerror ( errno ) );
67
71
return false;
68
72
}
69
73
70
74
jerry_port_log (JERRY_LOG_LEVEL_DEBUG , "Waiting for the client connection.\n" );
71
75
72
76
/* Connect from the client */
73
- connected = accept (sock , (struct sockaddr * )& client_addr , & sin_size );
77
+ if ((connected = accept (sock , (struct sockaddr * )& client_addr , & sin_size )) == -1 )
78
+ {
79
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error: %s\n" , strerror (errno ));
80
+ return false;
81
+ }
74
82
75
- jerry_port_log (JERRY_LOG_LEVEL_DEBUG ,"Connected from: %s:%d\n" ,
76
- inet_ntoa (client_addr .sin_addr ),ntohs (client_addr .sin_port ));
83
+ jerry_port_log (JERRY_LOG_LEVEL_DEBUG , "Connected from: %s:%d\n" ,
84
+ inet_ntoa (client_addr .sin_addr ), ntohs (client_addr .sin_port ));
77
85
78
86
return true;
79
87
} /* remote_init */
80
88
81
89
/* Close the socket connection with the client */
82
90
void connection_closed ()
83
91
{
84
- jerry_port_log (JERRY_LOG_LEVEL_DEBUG , "TCPServer connection closed on port %d. \n" , PORT );
92
+ jerry_port_log (JERRY_LOG_LEVEL_DEBUG , "TCPServer connection closed on port: %d\n" , PORT );
85
93
close (connected );
86
94
close (sock );
87
95
} /* connection_closed */
88
96
89
97
/* Send the parsed file names to the client side */
90
98
void send_to_client (uint16_t data_len ) /**< data length */
91
99
{
92
- ssize_t byte_send ;
93
-
94
- byte_send = send (connected , jerry_debugger_buffer , data_len , 0 );
100
+ ssize_t byte_send = send (connected , jerry_debugger_buffer , data_len , 0 );
95
101
96
102
/* If send returns -1 then some error messages are generated by the socket layer. */
97
103
if (byte_send == -1 )
@@ -102,6 +108,6 @@ void send_to_client (uint16_t data_len) /**< data length */
102
108
* information is sent to the client. */
103
109
else if (byte_send != (ssize_t ) data_len )
104
110
{
105
- jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error, missing bytes from the pacakge.. .\n" );
111
+ jerry_port_log (JERRY_LOG_LEVEL_ERROR , "Error: Missing bytes from the pacakge.\n" );
106
112
}
107
113
} /* send_to_client */
0 commit comments