• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "client_connection.h"
17 #include <cstdint>
18 #include <pthread.h>
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <unistd.h>
22 #include "logging.h"
23 
ClientConnection(int sfd,ServiceEntry & serviceEntry)24 ClientConnection::ClientConnection(int sfd, ServiceEntry& serviceEntry)
25 {
26     serviceBase_ = nullptr;
27     socketHandle_ = sfd;
28     clientState_ = CLIENT_STAT_WORKING;
29     lastProcMS_ = GetTimeMS();
30     serviceEntry_ = &serviceEntry;
31     HILOG_INFO(LOG_CORE, "new ClientConnection construct");
32     CreateRecvThread();
33 }
34 
~ClientConnection()35 ClientConnection::~ClientConnection() {}
36 
RawProtocolProc(uint32_t pnum,const int8_t * buf,const uint32_t size)37 int ClientConnection::RawProtocolProc(uint32_t pnum, const int8_t* buf, const uint32_t size)
38 {
39     switch (pnum) {
40         case RAW_PROTOCOL_POINTTO_SERVICE: {
41             struct RawPointToService* prrs = (struct RawPointToService*)buf;
42             protoServiceName_ = prrs->serviceName_;
43             serviceBase_ = const_cast<ServiceBase*>(serviceEntry_->FindServiceByName(protoServiceName_));
44             HILOG_INFO(LOG_CORE, "RAW_PROTOCOL_POINTTO_SERVICE %s", protoServiceName_.c_str());
45         }
46             return 1;
47         default:
48             break;
49     }
50     return -1;
51 }
52