Class: TinyDTLS::Session
- Inherits:
-
Object
- Object
- TinyDTLS::Session
- Defined in:
- lib/tinydtls/session.rb
Overview
This class offers a higher-level abstraction for the session_t type.
Instance Attribute Summary collapse
-
#addrinfo ⇒ Object
readonly
Returns the value of attribute addrinfo.
Class Method Summary collapse
-
.from_ptr(ptr) ⇒ Object
Creates a new instance of this class from a pointer to a
session_ttinydtls type.
Instance Method Summary collapse
-
#destroy!(ctx) ⇒ Object
Frees all resources associated with the underlying
session_ttinydtls type and reset any existing connections. -
#initialize(addrinfo) ⇒ Session
constructor
Creates a new instance of this class from the given Addrinfo.
-
#to_ptr ⇒ Object
Converts the object into a C pointer to a
session_ttinydtls type.
Constructor Details
#initialize(addrinfo) ⇒ Session
Creates a new instance of this class from the given Addrinfo.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tinydtls/session.rb', line 7 def initialize(addrinfo) @addrinfo = addrinfo unless @addrinfo.is_a? Addrinfo raise TypeError end sockaddr = @addrinfo.to_sockaddr @session = Wrapper::dtls_new_session(sockaddr, sockaddr.bytesize) if @session.null? raise Errno::ENOMEM end end |
Instance Attribute Details
#addrinfo ⇒ Object (readonly)
Returns the value of attribute addrinfo.
4 5 6 |
# File 'lib/tinydtls/session.rb', line 4 def addrinfo @addrinfo end |
Class Method Details
.from_ptr(ptr) ⇒ Object
Creates a new instance of this class from a pointer to a session_t tinydtls type. Such a pointer is, for instance, passed to the various tinydtls callback functions.
23 24 25 26 27 28 29 |
# File 'lib/tinydtls/session.rb', line 23 def self.from_ptr(ptr) lenptr = Wrapper::SocklenPtr.new sockaddr = Wrapper::dtls_session_addr(ptr, lenptr) addrinfo = Addrinfo.new(sockaddr.read_string(lenptr[:value])) return Session.new(addrinfo) end |
Instance Method Details
#destroy!(ctx) ⇒ Object
Frees all resources associated with the underlying session_t tinydtls type and reset any existing connections.
40 41 42 43 44 45 |
# File 'lib/tinydtls/session.rb', line 40 def destroy!(ctx) peer = Wrapper::dtls_get_peer(ctx, @session) unless peer.null? Wrapper::dtls_reset_peer(ctx, peer) end end |
#to_ptr ⇒ Object
Converts the object into a C pointer to a session_t tinydtls type. This pointer can be passed to various functions provided by TinyDTLS::Wrapper.
34 35 36 |
# File 'lib/tinydtls/session.rb', line 34 def to_ptr @session end |