Commit 51e03c49 authored by Alessandro Rubini's avatar Alessandro Rubini

general: check_packet is a network operation

Since check_packet is using network channels (file descriptors), it is
better declared as a network operations.  This allows, for example,
to make a simulator using ARCH=unix and only changing TIME= .
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 84df8890
...@@ -86,7 +86,7 @@ void unix_main_loop(struct pp_globals *ppg) ...@@ -86,7 +86,7 @@ void unix_main_loop(struct pp_globals *ppg)
ppg->ebest_updated = 0; ppg->ebest_updated = 0;
} }
i = unix_net_check_pkt(ppg, delay_ms); i = unix_net_ops.check_packet(ppg, delay_ms);
if (i < 0) if (i < 0)
continue; continue;
...@@ -96,7 +96,7 @@ void unix_main_loop(struct pp_globals *ppg) ...@@ -96,7 +96,7 @@ void unix_main_loop(struct pp_globals *ppg)
continue; continue;
} }
/* If delay_ms is -1, the above unix_net_check_pkt will continue /* If delay_ms is -1, the above ops.check_packet will continue
* consuming the previous timeout (see its implementation). * consuming the previous timeout (see its implementation).
* This ensures that every state machine is called at least once * This ensures that every state machine is called at least once
* every delay_ms */ * every delay_ms */
......
...@@ -14,6 +14,4 @@ struct unix_arch_data { ...@@ -14,6 +14,4 @@ struct unix_arch_data {
struct timeval tv; struct timeval tv;
}; };
extern int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms);
extern void unix_main_loop(struct pp_globals *ppg); extern void unix_main_loop(struct pp_globals *ppg);
...@@ -40,8 +40,6 @@ struct unix_arch_data { ...@@ -40,8 +40,6 @@ struct unix_arch_data {
struct timeval tv; struct timeval tv;
}; };
extern int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms);
extern void wrs_main_loop(struct pp_globals *ppg); extern void wrs_main_loop(struct pp_globals *ppg);
extern void wrs_init_ipcserver(struct minipc_ch *ppsi_ch); extern void wrs_init_ipcserver(struct minipc_ch *ppsi_ch);
......
...@@ -124,7 +124,7 @@ void wrs_main_loop(struct pp_globals *ppg) ...@@ -124,7 +124,7 @@ void wrs_main_loop(struct pp_globals *ppg)
ppg->ebest_updated = 0; ppg->ebest_updated = 0;
} }
i = unix_net_check_pkt(ppg, delay_ms); i = wrs_net_ops.check_packet(ppg, delay_ms);
if (i < 0) if (i < 0)
continue; continue;
...@@ -134,7 +134,7 @@ void wrs_main_loop(struct pp_globals *ppg) ...@@ -134,7 +134,7 @@ void wrs_main_loop(struct pp_globals *ppg)
continue; continue;
} }
/* If delay_ms is -1, the above unix_net_check_pkt will continue /* If delay_ms is -1, the above ops.check_packet will continue
* consuming the previous timeout (see its implementation). * consuming the previous timeout (see its implementation).
* This ensures that every state machine is called at least once * This ensures that every state machine is called at least once
* every delay_ms */ * every delay_ms */
......
...@@ -133,7 +133,7 @@ extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */ ...@@ -133,7 +133,7 @@ extern struct pp_ext_hooks pp_hooks; /* The one for the extension we build */
/* /*
* Network methods are encapsulated in a structure, so each arch only needs * Network methods are encapsulated in a structure, so each arch only needs
* to provide that structure. This should simplify management overall. * to provide that structure. This simplifies management overall.
*/ */
struct pp_network_operations { struct pp_network_operations {
int (*init)(struct pp_instance *ppi); int (*init)(struct pp_instance *ppi);
...@@ -143,6 +143,7 @@ struct pp_network_operations { ...@@ -143,6 +143,7 @@ struct pp_network_operations {
/* chtype here is PP_NP_GEN or PP_NP_EVT -- use_pdelay must be 0 */ /* chtype here is PP_NP_GEN or PP_NP_EVT -- use_pdelay must be 0 */
int (*send)(struct pp_instance *ppi, void *pkt, int len, int (*send)(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr); TimeInternal *t, int chtype, int use_pdelay_addr);
int (*check_packet)(struct pp_globals *ppg, int delay_ms);
}; };
/* This is the struct pp_network_operations to be provided by time- dir */ /* This is the struct pp_network_operations to be provided by time- dir */
......
...@@ -402,16 +402,7 @@ static int unix_net_exit(struct pp_instance *ppi) ...@@ -402,16 +402,7 @@ static int unix_net_exit(struct pp_instance *ppi)
return 0; return 0;
} }
struct pp_network_operations unix_net_ops = { static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
.init = unix_net_init,
.exit = unix_net_exit,
.recv = unix_net_recv,
.send = unix_net_send,
};
/* This function is called by main loops outside of the network operations */
int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms)
{ {
fd_set set; fd_set set;
int i, j, k; int i, j, k;
...@@ -481,3 +472,12 @@ int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms) ...@@ -481,3 +472,12 @@ int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms)
return ret; return ret;
} }
struct pp_network_operations unix_net_ops = {
.init = unix_net_init,
.exit = unix_net_exit,
.recv = unix_net_recv,
.send = unix_net_send,
.check_packet = unix_net_check_packet,
};
...@@ -477,9 +477,15 @@ static int wrs_net_exit(struct pp_instance *ppi) ...@@ -477,9 +477,15 @@ static int wrs_net_exit(struct pp_instance *ppi)
return 0; return 0;
} }
static int wrs_net_check_packet(struct pp_globals *ppg, int delay_ms)
{
return unix_net_ops.check_packet(ppg, delay_ms);
}
struct pp_network_operations wrs_net_ops = { struct pp_network_operations wrs_net_ops = {
.init = wrs_net_init, .init = wrs_net_init,
.exit = wrs_net_exit, .exit = wrs_net_exit,
.recv = wrs_net_recv, .recv = wrs_net_recv,
.send = wrs_net_send, .send = wrs_net_send,
.check_packet = wrs_net_check_packet,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment