Deferred instantiation of socket implmentations until registration.
Instantiating the implementations on plugin load was problematic in case multiple socket plugins were loaded. Now, the first one registered is instantiated.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
* Copyright (C) 2010 Martin Willi
|
||||
* Copyright (C) 2010 revosec AG
|
||||
*
|
||||
@@ -31,17 +33,13 @@ struct private_socket_raw_plugin_t {
|
||||
*/
|
||||
socket_raw_plugin_t public;
|
||||
|
||||
/**
|
||||
* Raw socket instance.
|
||||
*/
|
||||
socket_raw_socket_t *socket;
|
||||
};
|
||||
|
||||
METHOD(plugin_t, destroy, void,
|
||||
private_socket_raw_plugin_t *this)
|
||||
{
|
||||
charon->socket->remove_socket(charon->socket, &this->socket->socket);
|
||||
this->socket->destroy(this->socket);
|
||||
charon->socket->remove_socket(charon->socket,
|
||||
(socket_constructor_t)socket_raw_socket_create);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -58,15 +56,10 @@ plugin_t *socket_raw_plugin_create()
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
.socket = socket_raw_socket_create(),
|
||||
);
|
||||
|
||||
if (!this->socket)
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
charon->socket->add_socket(charon->socket, &this->socket->socket);
|
||||
charon->socket->add_socket(charon->socket,
|
||||
(socket_constructor_t)socket_raw_socket_create);
|
||||
|
||||
return &this->public.plugin;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
|
||||
* Copyright (C) 2006-2010 Tobias Brunner
|
||||
* Copyright (C) 2005-2010 Martin Willi
|
||||
* Copyright (C) 2006 Daniel Roethlisberger
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
@@ -612,7 +613,7 @@ static int open_recv_socket(private_socket_raw_socket_t *this, int family)
|
||||
return skt;
|
||||
}
|
||||
|
||||
METHOD(socket_raw_socket_t, destroy, void,
|
||||
METHOD(socket_t, destroy, void,
|
||||
private_socket_raw_socket_t *this)
|
||||
{
|
||||
if (this->recv4)
|
||||
@@ -654,8 +655,8 @@ socket_raw_socket_t *socket_raw_socket_create()
|
||||
.socket = {
|
||||
.send = _sender,
|
||||
.receive = _receiver,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.max_packet = lib->settings->get_int(lib->settings,
|
||||
"charon.max_packet", MAX_PACKET),
|
||||
|
||||
@@ -41,10 +41,6 @@ struct socket_raw_socket_t {
|
||||
*/
|
||||
socket_t socket;
|
||||
|
||||
/**
|
||||
* Destroy a socket_raw_socket_t.
|
||||
*/
|
||||
void (*destroy)(socket_raw_socket_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user