Show
Ignore:
Timestamp:
08/14/10 20:42:42 (22 months ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
994811461679afe70ab81e079fd87191d609be9d
Parents:
61975465b66e572def6105480f10917981b1ef0d
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (08/14/10 20:42:42)
Message:

[tls::session] Use ring buffers instead of dynamically growing buffers

This way enbuffering cannot throw bad_alloc.

Closes #69.

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tls/session.hh

    r8d4f7f7 r08f5bd7  
    2121#define GUARD_TLS_SESSION_HH 
    2222 
     23#include "ringbuf.hh" 
    2324#include "error_category.hh" 
    2425#include "init.hh" 
     
    4041                public boost::enable_shared_from_this<session_impl<Stream> > 
    4142        { 
     43                enum { ringbufsize = 4096 }; 
    4244        public: 
    4345                typedef boost::shared_ptr<session_impl<Stream> > ptr; 
     
    4951                        , stream(si) 
    5052                        , strand(stream.get_io_service()) 
    51                         , ins_low(0) 
    52                         , ins_high(0) 
     53                        , ins(ringbufsize) 
    5354                        , read_active(false) 
    54                         , outs_low(0) 
     55                        , outs(ringbufsize) 
    5556                        , write_active(false) 
    5657                        { init(tls_init, ce); } 
     
    6162                        , stream(si) 
    6263                        , strand(stream.get_io_service()) 
    63                         , ins_low(0) 
    64                         , ins_high(0) 
     64                        , ins(ringbufsize) 
    6565                        , read_active(false) 
    66                         , outs_low(0) 
     66                        , outs(ringbufsize) 
    6767                        , write_active(false) 
    6868                        { init(tls_init, ce); } 
     
    102102                gnutls_session_t gs; 
    103103 
    104                 /* the stuff that has been read but not yet passed on 
    105                  * is between ins_low and ins_high */ 
    106                 std::vector<unsigned char> ins; 
    107                 size_t ins_low, ins_high; 
     104                ringbuf ins; 
    108105                bool read_active; 
    109106                 
    110                 /* the stuff that has been buffered for sending but 
    111                  * not yet sent is between outs_low and the end of 
    112                  * outs */ 
    113                 std::vector<unsigned char> outs; 
    114                 size_t outs_low; 
     107                ringbuf outs; 
    115108                bool write_active; 
    116109