Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
transmit_file.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 <unistd.h>
23 
24 // SGCTP
25 #include "sgctp/payload.hpp"
26 #include "sgctp/transmit_file.hpp"
27 using namespace SGCTP;
28 
29 
30 //----------------------------------------------------------------------
31 // METHODS: CTransmit (implement/override)
32 //----------------------------------------------------------------------
33 
34 
35 int CTransmit_File::send( int _iFileDescriptor,
36  const void *_pBuffer,
37  int _iSize,
38  int _iFlags )
39 {
40  int __iReturn = ::write( _iFileDescriptor, _pBuffer, _iSize );
41  return
42  ( __iReturn >= 0 )
43  ? __iReturn
44  : -errno;
45 }
46 
47 int CTransmit_File::recv( int _iFileDescriptor,
48  void *_pBuffer,
49  int _iSize,
50  int _iFlags )
51 {
52  int __iReturn = ::read( _iFileDescriptor, _pBuffer, _iSize );
53  return
54  ( __iReturn >= 0 )
55  ? __iReturn
56  : -errno;
57 }
58 
60 {
61  return CTransmit::allocBuffer();
62 }
virtual int alloc()
Allocate resources required for data transmission (un-/serialization)
virtual int recv(int _iFileDescriptor, void *_pBuffer, int _iSize, int _iFlags)
Receive data from the given descriptor.
virtual int send(int _iFileDescriptor, const void *_pBuffer, int _iSize, int _iFlags)
Send data to the given descriptor.
int allocBuffer()
Allocate resources required for data transmission.
Definition: transmit.cpp:66