forked from rajneshrat/dpdk-tcpipstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_interface.c
71 lines (60 loc) · 1.36 KB
/
socket_interface.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
#include "tcp_in.h"
#include "tcp_tcb.h"
#include "socket_interface.h"
#include "types.h"
#include "tcp_common.h"
#include <pthread.h>
int
socket_open(STREAM_TYPE stream)
{
struct tcb *ptcb;
ptcb = alloc_tcb();
return ptcb->identifier;
}
int
socket_bind(int identifier, struct sock_addr *serv_addr)
{
struct tcb *ptcb;
int i;
ptcb = get_tcb_by_identifier(identifier);
if(ptcb == NULL) {
return -1; // use enum here
}
ptcb->ipv4_dst = serv_addr->ip;
ptcb->dport = serv_addr->port;
ptcb->sport = 0;
ptcb->state = LISTENING;
return 0;
}
int
socket_listen(int identifier, int queue_len)
{
struct tcb *ptcb;
ptcb = get_tcb_by_identifier(identifier);
// not implemented yet.
return 0; //SUCCESS
}
int
socket_accept(int ser_id, struct sock_addr *client_addr)
{
struct tcb *ptcb = NULL;
struct tcb *new_ptcb = NULL;
ptcb = get_tcb_by_identifier(ser_id);
if(ptcb->WaitingOnAccept) {
return 0;
// don't allow multiple accepts hold on same socket.
}
ptcb->state = LISTENING;
pthread_mutex_lock(&(ptcb->mutex));
ptcb->WaitingOnAccept = 1;
pthread_cond_wait(&(ptcb->condAccept), &(ptcb->mutex));
new_ptcb = ptcb->newpTcbOnAccept;
ptcb->WaitingOnAccept = 0;
pthread_mutex_unlock(&(ptcb->mutex));
return new_ptcb->identifier;
}
int
socket_close(int identifier)
{
return 0;
}