1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 pub enum SocketStatusCode { 17 Ok = 0, 18 Fail = -1, 19 FdFail = -2, 20 EpollFdFail = -3, 21 EpollCreateFail = -4, 22 EpollCtlFail = -5, 23 EpollWaitFail = -6, 24 EpollCloseFail = -7, 25 SocketCloseFail = -8, 26 SocketSetFdFail = -9, 27 } 28 29 pub enum BufferStatusCode { 30 Ok = 0, 31 Fail = -1, 32 ResetFail = -2, 33 CleanFail = -3, 34 UnreadSizeFail = -4, 35 IsEmptyFail = -5, 36 WriteStreamBufferFail = -6, 37 ReadStreamBufferFail = -7, 38 CheckRWErrorFail = -8, 39 CopyDataToBeginFail = -9, 40 ReadCharUsizeFail = -10, 41 ReadServerPacketsFail = -11, 42 ReadClientPacketsFail = -12, 43 SizeFail = -13, 44 RcountFail = -14, 45 WcountFail = -15, 46 WposFail = -16, 47 RposFail = -17, 48 SetRwErrStatusFail = -18, 49 SetRposFail = -19, 50 } 51 52 pub enum SessionStatusCode { 53 Ok = 0, 54 Fail = -1, 55 UidFail = -2, 56 PidFail = -3, 57 ModuleTypeFail = -4, 58 FdFail = -5, 59 SetTokenTypeFail = -6, 60 TokenTypeFail = -7, 61 CloseFail = -8, 62 SetUidFail = -9, 63 SetFdFail = -10, 64 SetPidFail = -11, 65 } 66 67 pub enum NetPacketStatusCode { 68 Ok = 0, 69 Fail = -1, 70 PacketLengthFail = -2, 71 } 72 73 impl From<SocketStatusCode> for i32 { from(code: SocketStatusCode) -> i3274 fn from(code: SocketStatusCode) -> i32 { 75 match code { 76 SocketStatusCode::Ok => 0, 77 SocketStatusCode::FdFail => -2, 78 SocketStatusCode::EpollFdFail => -3, 79 SocketStatusCode::EpollCreateFail => -4, 80 SocketStatusCode::EpollCtlFail => -5, 81 SocketStatusCode::EpollWaitFail => -6, 82 SocketStatusCode::EpollCloseFail => -7, 83 SocketStatusCode::SocketCloseFail => -8, 84 SocketStatusCode::SocketSetFdFail => -9, 85 _ => -1, 86 } 87 } 88 } 89 90 impl From<BufferStatusCode> for i32 { from(code: BufferStatusCode) -> i3291 fn from(code: BufferStatusCode) -> i32 { 92 match code { 93 BufferStatusCode::Ok => 0, 94 BufferStatusCode::ResetFail => -2, 95 BufferStatusCode::CleanFail => -3, 96 BufferStatusCode::UnreadSizeFail => -4, 97 BufferStatusCode::IsEmptyFail => -5, 98 BufferStatusCode::WriteStreamBufferFail => -6, 99 BufferStatusCode::ReadStreamBufferFail => -7, 100 BufferStatusCode::CheckRWErrorFail => -8, 101 BufferStatusCode::CopyDataToBeginFail => -9, 102 BufferStatusCode::ReadCharUsizeFail => -10, 103 BufferStatusCode::ReadServerPacketsFail => -11, 104 BufferStatusCode::ReadClientPacketsFail => -12, 105 BufferStatusCode::SizeFail => -13, 106 BufferStatusCode::RcountFail => -14, 107 BufferStatusCode::WcountFail => -15, 108 BufferStatusCode::WposFail => -16, 109 BufferStatusCode::RposFail => -17, 110 BufferStatusCode::SetRwErrStatusFail => -18, 111 BufferStatusCode::SetRposFail => -19, 112 _ => -1, 113 } 114 } 115 } 116 117 impl From<SessionStatusCode> for i32 { from(code: SessionStatusCode) -> i32118 fn from(code: SessionStatusCode) -> i32 { 119 match code { 120 SessionStatusCode::Ok => 0, 121 SessionStatusCode::UidFail => -2, 122 SessionStatusCode::PidFail => -3, 123 SessionStatusCode::ModuleTypeFail => -4, 124 SessionStatusCode::FdFail => -5, 125 SessionStatusCode::SetTokenTypeFail => -6, 126 SessionStatusCode::TokenTypeFail => -7, 127 SessionStatusCode::CloseFail => -8, 128 SessionStatusCode::SetUidFail => -9, 129 SessionStatusCode::SetFdFail => -10, 130 SessionStatusCode::SetPidFail => -11, 131 _ => -1, 132 } 133 } 134 } 135 136 impl From<NetPacketStatusCode> for i32 { from(code: NetPacketStatusCode) -> i32137 fn from(code: NetPacketStatusCode) -> i32 { 138 match code { 139 NetPacketStatusCode::Ok => 0, 140 NetPacketStatusCode::PacketLengthFail => -2, 141 _ => -1, 142 } 143 } 144 }