Implement file close in network tranference.

Stop receiving packets from card on error.
This commit is contained in:
Manoel Rebelo Abranches 2011-05-10 09:32:38 -03:00
parent 1893017d44
commit 4d6374ba78
2 changed files with 29 additions and 5 deletions

View file

@ -27,6 +27,7 @@
grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL; grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL;
grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL; grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL;
grub_err_t (*grub_file_net_close) (grub_file_t file) = NULL;
grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL; grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL;
grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
@ -176,7 +177,10 @@ grub_err_t
grub_file_close (grub_file_t file) grub_file_close (grub_file_t file)
{ {
if (file->device->net) if (file->device->net)
{
grub_file_net_close (file);
return grub_errno; return grub_errno;
}
if (file->fs->close) if (file->fs->close)
(file->fs->close) (file); (file->fs->close) (file);

View file

@ -619,18 +619,35 @@ fail:
} }
static grub_err_t
grub_net_file_close_real (grub_file_t file)
{
grub_net_socket_t sock = file->device->net->socket;
while (sock->packs->first)
{
grub_netbuff_free (sock->packs->first->nb);
grub_net_remove_packet (sock->packs->first);
}
grub_net_socket_unregister (sock);
grub_free (sock);
return GRUB_ERR_NONE;
}
static grub_err_t static grub_err_t
receive_packets (struct grub_net_card *card) receive_packets (struct grub_net_card *card)
{ {
/* Maybe should be better have a fixed number of packets for each card /* Maybe should be better have a fixed number of packets for each card
and just mark them as used and not used. */ and just mark them as used and not used. */
struct grub_net_buff *nb; struct grub_net_buff *nb;
grub_err_t err;
nb = grub_netbuff_alloc (1500); nb = grub_netbuff_alloc (1500);
if (!nb) if (!nb)
return grub_errno; return grub_errno;
card->driver->recv (card, nb); if ((err = card->driver->recv (card, nb)) != GRUB_ERR_NONE)
return GRUB_ERR_NONE; grub_netbuff_free (nb);
return err;
} }
void void
@ -642,7 +659,8 @@ grub_net_pool_cards (unsigned time)
{ {
start_time = grub_get_time_ms (); start_time = grub_get_time_ms ();
while( (grub_get_time_ms () - start_time) < time) while( (grub_get_time_ms () - start_time) < time)
receive_packets (card); if( receive_packets (card) != GRUB_ERR_NONE)
break;
} }
} }
@ -1018,6 +1036,7 @@ GRUB_MOD_INIT(net)
grub_net_open = grub_net_open_real; grub_net_open = grub_net_open_real;
grub_file_net_open = grub_net_file_open_real; grub_file_net_open = grub_net_file_open_real;
grub_file_net_close = grub_net_file_close_real;
grub_file_net_read = grub_net_read_real; grub_file_net_read = grub_net_read_real;
grub_file_net_seek = grub_net_seek_real; grub_file_net_seek = grub_net_seek_real;
} }
@ -1034,4 +1053,5 @@ GRUB_MOD_FINI(net)
grub_net_open = NULL; grub_net_open = NULL;
grub_file_net_read = NULL; grub_file_net_read = NULL;
grub_file_net_open = NULL; grub_file_net_open = NULL;
grub_file_net_close = NULL;
} }