Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
transmit_udp.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Simple Geolocalization and Course Transmission Protocol (SGCTP)
5  * Copyright (C) 2014 Cedric Dufour <http://cedric.dufour.name>
6  *
7  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
8  * free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
13  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License for more details.
18  */
19 
20 // C
21 #include <errno.h>
22 #include <sys/socket.h>
23 
24 // SGCTP
25 #include "sgctp/payload.hpp"
26 #include "sgctp/transmit_udp.hpp"
27 using namespace SGCTP;
28 
29 
30 //----------------------------------------------------------------------
31 // METHODS: CTransmit (implement/override)
32 //----------------------------------------------------------------------
33 
34 int CTransmit_UDP::send( int _iSocket,
35  const void *_pBuffer,
36  int _iSize,
37  int _iFlags )
38 {
39  int __iReturn = ::sendto( _iSocket, _pBuffer, _iSize, _iFlags,
41  return
42  ( __iReturn >= 0 )
43  ? __iReturn
44  : -errno;
45 }
46 
47 int CTransmit_UDP::recv( int _iSocket,
48  void *_pBuffer,
49  int _iSize,
50  int _iFlags )
51 {
52  int __iReturn = ::recvfrom( _iSocket, _pBuffer, _iSize, _iFlags,
54  return
55  ( __iReturn >= 0 )
56  ? __iReturn
57  : -errno;
58 }
59 
61 {
62  return CTransmit::allocBuffer();
63 }
64 
65 int CTransmit_UDP::unserialize( int _iDescriptor,
66  CData *_poData,
67  int _iMaxSize )
68 {
69  // Unserialize
70  int __iReturn = CTransmit::unserialize( _iDescriptor,
71  _poData,
72  _iMaxSize );
73 
74  // Discard remaining buffer data (NOTE: help recover from corrupted data)
75  resetBuffer();
76 
77  // Done
78  return __iReturn;
79 }
80 
virtual int unserialize(int _iDescriptor, CData *_poData, int _iMaxSize=0)
Unserialize the SGCTP data from the given descriptor.
virtual int send(int _iSocket, const void *_pBuffer, int _iSize, int _iFlags)
Send data to the given descriptor.
SGCTP data container.
Definition: data.hpp:44
virtual int recv(int _iSocket, void *_pBuffer, int _iSize, int _iFlags)
Receive data from the given descriptor.
virtual int alloc()
Allocate resources required for data transmission (un-/serialization)
socklen_t * ptSocklenT
Network socket address length (pointer to existing variable)
Definition: parameters.hpp:51
void resetBuffer()
Reset the data buffer (clear all data)
Definition: transmit.cpp:146
virtual int unserialize(int _iDescriptor, CData *_poData, int _iMaxSize=0)
Unserialize the SGCTP data from the given descriptor.
Definition: transmit.cpp:256
struct sockaddr * ptSockaddr
Network socket address (pointer to existing variable)
Definition: parameters.hpp:49
int allocBuffer()
Allocate resources required for data transmission.
Definition: transmit.cpp:66