Home | History | Annotate | Download | only in microspdy
      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_raw.h
     21  * @brief  IO for SPDY without TLS.
     22  * @author Andrey Uzunov
     23  */
     24 
     25 #ifndef IO_RAW_H
     26 #define IO_RAW_H
     27 
     28 #include "platform.h"
     29 
     30 
     31 /**
     32  * Must be called only once in the program.
     33  *
     34  */
     35 void
     36 SPDYF_raw_global_init();
     37 
     38 
     39 /**
     40  * Should be called
     41  * at the end of the program.
     42  *
     43  */
     44 void
     45 SPDYF_raw_global_deinit();
     46 
     47 
     48 /**
     49  * Must be called when the daemon starts.
     50  *
     51  * @param daemon SPDY_Daemon
     52  * @return SPDY_YES on success or SPDY_NO on error
     53  */
     54 int
     55 SPDYF_raw_init(struct SPDY_Daemon *daemon);
     56 
     57 
     58 /**
     59  * Should be called
     60  * when the deamon is stopped.
     61  *
     62  * @param daemon SPDY_Daemon which is being stopped
     63  */
     64 void
     65 SPDYF_raw_deinit(struct SPDY_Daemon *daemon);
     66 
     67 
     68 /**
     69  * Must be called
     70  * after the connection has been accepted.
     71  *
     72  * @param session SPDY_Session whose socket will be used
     73  * @return SPDY_NO if some funcs fail. SPDY_YES otherwise
     74  */
     75 int
     76 SPDYF_raw_new_session(struct SPDY_Session *session);
     77 
     78 
     79 /**
     80  * Should be called
     81  * closing session's socket.
     82  *
     83  * @param session SPDY_Session whose socket is used
     84  */
     85 void
     86 SPDYF_raw_close_session(struct SPDY_Session *session);
     87 
     88 
     89 /**
     90  * Reading from socket. Reads available data and put it to the
     91  * buffer.
     92  *
     93  * @param session for which data is received
     94  * @param buffer where data from the socket will be written to
     95  * @param size of the buffer
     96  * @return number of bytes (at most size) read from the connection
     97  *         0 if the other party has closed the connection
     98  *         SPDY_IO_ERROR code on error
     99  */
    100 int
    101 SPDYF_raw_recv(struct SPDY_Session *session,
    102 				void * buffer,
    103 				size_t size);
    104 
    105 
    106 /**
    107  * Writing to socket. Writes the data given into the buffer to the
    108  * socket.
    109  *
    110  * @param session whose context is used
    111  * @param buffer from where data will be written to the socket
    112  * @param size number of bytes to be taken from the buffer
    113  * @return number of bytes (at most size) from the buffer that has been
    114  * 			written to the connection
    115  *         0 if the other party has closed the connection
    116  *         SPDY_IO_ERROR code on error
    117  */
    118 int
    119 SPDYF_raw_send(struct SPDY_Session *session,
    120 				const void * buffer,
    121 				size_t size);
    122 
    123 
    124 /**
    125  * Checks if there is data staying in the buffers of the underlying
    126  * system that waits to be read. Always returns SPDY_NO, as we do not
    127  * use a subsystem here.
    128  *
    129  * @param session which is checked
    130  * @return SPDY_YES if data is pending or SPDY_NO otherwise
    131  */
    132 int
    133 SPDYF_raw_is_pending(struct SPDY_Session *session);
    134 
    135 
    136 /**
    137  * Sets TCP_CORK.
    138  *
    139  * @param session
    140  * @return SPDY_NO if writing must not happen in the call;
    141  *         SPDY_YES otherwise
    142  */
    143 int
    144 SPDYF_raw_before_write(struct SPDY_Session *session);
    145 
    146 
    147 /**
    148  * Unsets TCP_CORK.
    149  *
    150  * @param session
    151  * @param was_written has the same value as the write function for the
    152  *        session will return
    153  * @return returned value will be used by the write function to return
    154  */
    155 int
    156 SPDYF_raw_after_write(struct SPDY_Session *session, int was_written);
    157 
    158 #endif
    159