1 /*
2     This file is part of libmicrospdy
3     Copyright Copyright (C) 2013 Andrey Uzunov
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file io.c
21  * @brief Generic functions for IO.
22  * @author Andrey Uzunov
23  */
24 
25 #include "platform.h"
26 #include "structures.h"
27 #include "internal.h"
28 #include "io.h"
29 
30 
31 int
SPDYF_io_set_daemon(struct SPDY_Daemon * daemon,enum SPDY_IO_SUBSYSTEM io_subsystem)32 SPDYF_io_set_daemon(struct SPDY_Daemon *daemon,
33                     enum SPDY_IO_SUBSYSTEM io_subsystem)
34 {
35   switch(io_subsystem)
36   {
37     case SPDY_IO_SUBSYSTEM_OPENSSL:
38       daemon->fio_init = &SPDYF_openssl_init;
39       daemon->fio_deinit = &SPDYF_openssl_deinit;
40       break;
41 
42     case SPDY_IO_SUBSYSTEM_RAW:
43       daemon->fio_init = &SPDYF_raw_init;
44       daemon->fio_deinit = &SPDYF_raw_deinit;
45       break;
46 
47     case SPDY_IO_SUBSYSTEM_NONE:
48     default:
49       SPDYF_DEBUG("Unsupported subsystem");
50       return SPDY_NO;
51   }
52 
53   return SPDY_YES;
54 }
55 
56 
57 int
SPDYF_io_set_session(struct SPDY_Session * session,enum SPDY_IO_SUBSYSTEM io_subsystem)58 SPDYF_io_set_session(struct SPDY_Session *session,
59                      enum SPDY_IO_SUBSYSTEM io_subsystem)
60 {
61   switch(io_subsystem)
62   {
63     case SPDY_IO_SUBSYSTEM_OPENSSL:
64       session->fio_new_session = &SPDYF_openssl_new_session;
65       session->fio_close_session = &SPDYF_openssl_close_session;
66       session->fio_is_pending = &SPDYF_openssl_is_pending;
67       session->fio_recv = &SPDYF_openssl_recv;
68       session->fio_send = &SPDYF_openssl_send;
69       session->fio_before_write = &SPDYF_openssl_before_write;
70       session->fio_after_write = &SPDYF_openssl_after_write;
71       break;
72 
73     case SPDY_IO_SUBSYSTEM_RAW:
74       session->fio_new_session = &SPDYF_raw_new_session;
75       session->fio_close_session = &SPDYF_raw_close_session;
76       session->fio_is_pending = &SPDYF_raw_is_pending;
77       session->fio_recv = &SPDYF_raw_recv;
78       session->fio_send = &SPDYF_raw_send;
79       session->fio_before_write = &SPDYF_raw_before_write;
80       session->fio_after_write = &SPDYF_raw_after_write;
81       break;
82 
83     case SPDY_IO_SUBSYSTEM_NONE:
84     default:
85       SPDYF_DEBUG("Unsupported subsystem");
86       return SPDY_NO;
87   }
88 
89   return SPDY_YES;
90 }
91