* Separated create_socket() and the call to the protocol's open() function - open()

is not supposed to be called for accepted sockets, only for those created via
  a call the userland socket() function.
* Renamed net_socket_module_info::socket() to open_socket() to make this distinction
  a bit clearer.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19254 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-11-11 11:56:52 +00:00
parent 76d115d893
commit b70a062dc5
3 changed files with 29 additions and 12 deletions

View File

@ -51,7 +51,7 @@ typedef struct net_socket {
struct net_socket_module_info {
struct module_info info;
status_t (*socket)(int family, int type, int protocol, net_socket **_socket);
status_t (*open_socket)(int family, int type, int protocol, net_socket **_socket);
status_t (*close)(net_socket *socket);
status_t (*free)(net_socket *socket);

View File

@ -409,7 +409,8 @@ net_stack_control(void *_cookie, uint32 op, void *data, size_t length)
if (status < B_OK)
return status;
return sSocket->socket(args.family, args.type, args.protocol, &cookie->socket);
return sSocket->open_socket(args.family, args.type,
args.protocol, &cookie->socket);
}
case NET_STACK_GET_COOKIE:

View File

@ -25,8 +25,8 @@
void socket_delete(net_socket *socket);
status_t
socket_create(int family, int type, int protocol, net_socket **_socket)
static status_t
create_socket(int family, int type, int protocol, net_socket **_socket)
{
struct net_socket *socket = new (std::nothrow) net_socket;
if (socket == NULL)
@ -55,15 +55,9 @@ socket_create(int family, int type, int protocol, net_socket **_socket)
if (status < B_OK)
goto err2;
status = socket->first_info->open(socket->first_protocol);
if (status < B_OK)
goto err3;
*_socket = socket;
return B_OK;
err3:
put_domain_protocols(socket);
err2:
benaphore_destroy(&socket->lock);
err1:
@ -72,6 +66,28 @@ err1:
}
// #pragma mark -
status_t
socket_open(int family, int type, int protocol, net_socket **_socket)
{
net_socket *socket;
status_t status = create_socket(family, type, protocol, &socket);
if (status < B_OK)
return status;
status = socket->first_info->open(socket->first_protocol);
if (status < B_OK) {
socket_delete(socket);
return status;
}
*_socket = socket;
return B_OK;
}
status_t
socket_close(net_socket *socket)
{
@ -200,7 +216,7 @@ socket_spawn_pending(net_socket *parent, net_socket **_socket)
return ENOBUFS;
net_socket *socket;
status_t status = socket_create(parent->family, parent->type, parent->protocol, &socket);
status_t status = create_socket(parent->family, parent->type, parent->protocol, &socket);
if (status < B_OK)
return status;
@ -797,7 +813,7 @@ net_socket_module_info gNetSocketModule = {
0,
socket_std_ops
},
socket_create,
socket_open,
socket_close,
socket_free,