research2 : architecture update
[swifty.git] / doc / research1 / API.txt
1 This is the swift structures:
2 // swift interface
3 typedef struct swift {
4         int socketListener, socketData;
5         struct sockaddr_in socketListenerAddr;
6 } *Swift;
7
8 // swift_addr structure similar with in_addr 
9 struct swift_addr {
10         unsigned short N;                       // e.g. number of s_addr
11         unsigned long s_addr[MAX_IPs];          // i.p. ip list
12 };
13
14 // swift struct similar with sock_addr
15 typedef struct sockSwiftaddr {
16     short               sin_family;             // e.g. AF_INET
17     unsigned short      sin_port;               // e.g. htons(3490)
18     struct swift_addr   sin_addr;               // see struct swift_addr, below
19 } *SockSwiftaddr;
20
21 // list of swift_addr
22 struct listsockaddr {
23         unsigned short N;
24         struct sockaddr_in sa[MAX_IPs];
25 };
26
27 With this new structures we modify the normal socket api and the new api is:
28
29 // Function to create a Swift socket
30 Swift socketSwift();
31
32 // Function to close a Swift socket
33 void closeSwift(Swift);
34
35 // Function to listen to a port
36 int listenfromSwift (Swift s, void *buf, size_t len, int flags,
37                  struct sockSwiftaddr * __restrict__ from, socklen_t *fromlen);
38
39 // Function to bind a port for swift socket
40 int bindSwift(Swift s, const struct sockSwiftaddr *my_addr, socklen_t addrlen);
41
42 // Function to receive a message
43 ssize_t recvFromSwift(Swift s, void *buf, size_t len, int flags,
44                  struct sockSwiftaddr *from, socklen_t *fromlen);
45                  
46 // Function to send a message
47 ssize_t sendToSwift(Swift s, const void *buf, size_t len, int flags, 
48                                 const struct sockSwiftaddr *to, socklen_t tolen);