Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added sock_set functions for select() support
[palacios.git] / palacios / src / palacios / vmm_socket.c
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <palacios/vmm_socket.h>
22 #include <palacios/vmm.h>
23
24
25 struct v3_socket_hooks * sock_hooks = 0;
26
27
28
29
30 void V3_Init_Sockets(struct v3_socket_hooks * hooks) {
31   PrintInfo("Initializing Socket Interface\n");
32   sock_hooks = hooks;
33 }
34
35
36
37 void v3_init_sock_set(struct v3_sock_set * sock_set) {
38   sock_set->num_socks = 0;
39   sock_set->socks = NULL;
40
41 }
42
43
44
45
46
47 /* This should probably check if the socket is already added */
48 // adds socket to the sockset
49 void v3_set_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
50   struct v3_sock_entry * new_entry = V3_Malloc(sizeof(struct v3_sock_entry));
51
52   new_entry->sock = sock;
53   new_entry->is_set = 0;
54
55   if (sock_set->socks) {
56     new_entry->next = sock_set->socks;
57   }
58
59   sock_set->socks = new_entry;
60
61   sock_set->num_socks++;
62 }
63
64
65 // deletes socket from sockset
66 void v3_clr_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
67   struct v3_sock_entry * iter, * back_ptr;
68
69   iter = sock_set->socks;
70   back_ptr = NULL;
71
72   v3_foreach_sock(sock_set, iter) {
73     if (iter->sock == sock) {
74       if (back_ptr == NULL) {
75         sock_set->socks = iter->next;
76       } else {
77         back_ptr->next = iter->next;
78       }
79
80       V3_Free(iter);
81
82       sock_set->num_socks--;
83       break;
84     }
85
86     back_ptr = iter;
87   }
88 }
89
90 // checks is_set vairable 
91 int v3_isset_sock(struct v3_sock_set * sock_set, V3_SOCK sock) {
92   struct v3_sock_entry * iter;
93
94   v3_foreach_sock(sock_set, iter) {
95     if (iter->sock == sock) {
96       return iter->is_set;
97     }
98   }
99   return -1;
100 }
101
102
103 // clears all is_set variables.
104 void v3_zero_sockset(struct v3_sock_set * sock_set) {
105   struct v3_sock_entry * iter;
106   v3_foreach_sock(sock_set, iter) {
107     iter->is_set = 0;
108   }
109 }