| 1 | /* |
|---|
| 2 | * Copyright (c) 2010, |
|---|
| 3 | * Gavriloaie Eugen-Andrei (shiretu@gmail.com) |
|---|
| 4 | * |
|---|
| 5 | * This file is part of crtmpserver. |
|---|
| 6 | * crtmpserver is free software: you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * crtmpserver is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with crtmpserver. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include "protocols/tcpprotocol.h" |
|---|
| 22 | #include "netio/netio.h" |
|---|
| 23 | |
|---|
| 24 | TCPProtocol::TCPProtocol() |
|---|
| 25 | : BaseProtocol(PT_TCP) { |
|---|
| 26 | _decodedBytesCount = 0; |
|---|
| 27 | _pCarrier = NULL; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | TCPProtocol::~TCPProtocol() { |
|---|
| 31 | if (_pCarrier != NULL) { |
|---|
| 32 | IOHandler *pCarrier = _pCarrier; |
|---|
| 33 | _pCarrier = NULL; |
|---|
| 34 | pCarrier->SetProtocol(NULL); |
|---|
| 35 | delete pCarrier; |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | bool TCPProtocol::Initialize(Variant ¶meters) { |
|---|
| 40 | return true; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | IOHandler *TCPProtocol::GetIOHandler() { |
|---|
| 44 | return _pCarrier; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | void TCPProtocol::SetIOHandler(IOHandler *pIOHandler) { |
|---|
| 48 | if (pIOHandler != NULL) { |
|---|
| 49 | if ((pIOHandler->GetType() != IOHT_TCP_CARRIER) |
|---|
| 50 | && (pIOHandler->GetType() != IOHT_STDIO)) { |
|---|
| 51 | ASSERT("This protocol accepts only TCP carriers"); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | _pCarrier = pIOHandler; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | bool TCPProtocol::AllowFarProtocol(uint64_t type) { |
|---|
| 58 | WARN("This protocol doesn't accept any far protocol"); |
|---|
| 59 | return false; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | bool TCPProtocol::AllowNearProtocol(uint64_t type) { |
|---|
| 63 | return true; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | IOBuffer * TCPProtocol::GetInputBuffer() { |
|---|
| 67 | return &_inputBuffer; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | bool TCPProtocol::SignalInputData(int32_t recvAmount) { |
|---|
| 71 | _decodedBytesCount += recvAmount; |
|---|
| 72 | return _pNearProtocol->SignalInputData(_inputBuffer); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | bool TCPProtocol::SignalInputData(IOBuffer & /* ignored */) { |
|---|
| 76 | ASSERT("OPERATION NOT SUPPORTED"); |
|---|
| 77 | return false; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | bool TCPProtocol::EnqueueForOutbound() { |
|---|
| 81 | if (_pCarrier == NULL) { |
|---|
| 82 | FATAL("TCPProtocol has no carrier"); |
|---|
| 83 | return false; |
|---|
| 84 | } |
|---|
| 85 | return _pCarrier->SignalOutputData(); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | uint64_t TCPProtocol::GetDecodedBytesCount() { |
|---|
| 89 | return _decodedBytesCount; |
|---|
| 90 | } |
|---|
| 91 | |
|---|