Initial revision
[silc.git] / lib / silccore / silcsockconn.c
1 /*
2
3   silcsockconn.c
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20 /*
21  * $Id$
22  * $Log$
23  * Revision 1.1  2000/06/27 11:36:55  priikone
24  * Initial revision
25  *
26  *
27  */
28
29 #include "silcincludes.h"
30
31 /* Allocates a new socket connection object. The allocated object is 
32    returned to the new_socket argument. */
33
34 void silc_socket_alloc(int sock, SilcSocketType type, void *user_data, 
35                        SilcSocketConnection *new_socket)
36 {
37   SILC_LOG_DEBUG(("Allocating new socket connection object"));
38
39   *new_socket = silc_calloc(1, sizeof(**new_socket));
40   if (*new_socket == NULL) {
41     SILC_LOG_ERROR(("Could not allocate new socket connection object"));
42     return;
43   }
44
45   /* Set the pointers. Incoming and outgoing data buffers
46      are allocated by the server when they are first used. */
47   (*new_socket)->sock = sock;
48   (*new_socket)->type = type;
49   (*new_socket)->user_data = user_data;
50   (*new_socket)->protocol = NULL;
51   (*new_socket)->flags = 0;
52   (*new_socket)->inbuf = NULL;
53   (*new_socket)->outbuf = NULL;
54 }
55
56 /* Free's the Socket connection object. */
57
58 void silc_socket_free(SilcSocketConnection sock)
59 {
60   if (sock) {
61     //    silc_protocol_free(sock->protocol);
62     silc_buffer_free(sock->inbuf);
63     silc_buffer_free(sock->outbuf);
64     silc_free(sock);
65   }
66 }