mirror of https://github.com/EdgeVPNio/evio.git
115 lines
3.0 KiB
C++
115 lines
3.0 KiB
C++
/*
|
|
* EdgeVPNio
|
|
* Copyright 2020, University of Florida
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
#ifndef TINCAN_ASYNCIO_H_
|
|
#define TINCAN_ASYNCIO_H_
|
|
#include "rtc_base/logging.h"
|
|
#if defined(_TNC_WIN)
|
|
#include <Winsock2.h>
|
|
#include <minwinbase.h>
|
|
#endif
|
|
|
|
#include "tincan_base.h"
|
|
|
|
namespace tincan
|
|
{
|
|
enum AIO_OP
|
|
{
|
|
AIO_READ,
|
|
AIO_WRITE,
|
|
AIO_MAX
|
|
};
|
|
|
|
struct AsyncIo
|
|
#if defined(_TNC_WIN)
|
|
: public OVERLAPPED
|
|
#endif // defined(_TNC_WIN)
|
|
{
|
|
AsyncIo() :
|
|
buffer_to_transfer_(nullptr),
|
|
context_(nullptr),
|
|
bytes_to_transfer_(0),
|
|
bytes_transferred_(0),
|
|
flags_(AIO_READ),
|
|
good_(true)
|
|
{
|
|
#if defined(_TNC_WIN)
|
|
ZeroMemory(this, sizeof(OVERLAPPED));
|
|
#endif // defined(_TNC_WIN)
|
|
}
|
|
|
|
AsyncIo(
|
|
uint8_t* buffer,
|
|
uint32_t bytes_to_transfer,
|
|
void* context,
|
|
AIO_OP flags,
|
|
uint32_t bytes_transferred = 0) :
|
|
buffer_to_transfer_(buffer),
|
|
context_(context),
|
|
bytes_to_transfer_(bytes_to_transfer),
|
|
bytes_transferred_(bytes_transferred),
|
|
flags_(flags),
|
|
good_(true)
|
|
{
|
|
#if defined(_TNC_WIN)
|
|
ZeroMemory(this, sizeof(OVERLAPPED));
|
|
#endif // defined(_TNC_WIN)
|
|
}
|
|
|
|
AsyncIo(AsyncIo & rhs);
|
|
|
|
#if !defined(_TNC_WIN)
|
|
virtual ~AsyncIo() = default;
|
|
#endif // defined(_TNC_WIN)
|
|
|
|
void Initialize(
|
|
uint8_t* buffer_to_transfer,
|
|
uint32_t bytes_to_transfer,
|
|
void* context,
|
|
AIO_OP flags,
|
|
uint32_t bytes_transferred);
|
|
AsyncIo &operator= (const AsyncIo & rhs);
|
|
bool operator==(const AsyncIo & rhs) const;
|
|
bool operator!=(const AsyncIo & rhs) const;
|
|
void BufferToTransfer(uint8_t* val);
|
|
uint8_t* BufferToTransfer();
|
|
void BytesToTransfer(uint32_t val);
|
|
uint32_t BytesToTransfer();
|
|
void BytesTransferred(uint32_t val);
|
|
uint32_t BytesTransferred();
|
|
void Context(void * val);
|
|
void * Context();
|
|
bool IsRead();
|
|
void SetReadOp();
|
|
bool IsWrite();
|
|
void SetWriteOp();
|
|
bool IsGood();
|
|
uint8_t * buffer_to_transfer_;
|
|
void * context_;
|
|
uint32_t bytes_to_transfer_;
|
|
uint32_t bytes_transferred_;
|
|
AIO_OP flags_;
|
|
bool good_;
|
|
};
|
|
}
|
|
#endif// TINCAN_ASYNCIO_H_
|