-
Notifications
You must be signed in to change notification settings - Fork 0
/
assist-server.c
74 lines (61 loc) · 1.72 KB
/
assist-server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** @file assist-server.c
* @brief Starting point of execution. Create socket and wait in while loop.
*
* main() function create a socket (tcp/ip) and go in while loop for accepting connection.
* Once new request from DUT, accept the conenction and start processing the request
*
* @author Yashwanth Dasar (yashwanth_dasar@mentor.com)
* @bug No know bugs.
*/
#include "include/assist.h"
/** @file assist-server.c
* @brief Starting point of execution. Create socket and wait in while loop
*
* main() function create a socket (tcp/ip) and go in while loop for accepting connection.
* Once new request from DUT, accept the conenction and start processing the request
*
* @param none
* @return 0 on success and -1 on failure
*/
int main(void)
{
int sockfd, connfd, sockaddr_len;
struct sockaddr_in dut_addr;
if((sockfd = create_socket()) == -1)
{
printf("\nAssist : Create socket fail\n");
return -1;
}
#ifdef DEBUG
else
{
printf("\nAssist : Create socket pass\n");
}
#endif
// loop indefinitely for wait or listen or receive mode
while(1)
{
sockaddr_len = sizeof(dut_addr);
// Accept connection from peer
if((connfd = accept(sockfd, (struct sockaddr *)&dut_addr, (socklen_t*)&sockaddr_len)) < 0)
{
printf("\nAssist : Accept fail\n");
continue;
}
else
{
printf("\n============New connection==============\n");
}
// Start receiving the requests or commands from DUT board
if(service_request(connfd) == -1)
{
printf("\nAssist : Something went wrong at assist board. Please check\n");
if(write_socket("\nAssist : Something went wrong at assist board. Please check. AssistBoardClose", connfd) != 0)
{
continue;
}
}
}
close(sockfd);
return 0;
}