blob: 8ebb6510eba356dd25685d1b3bf355247f885cc0 [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001// Copyright 2021 Google LLC
2//
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
William A. Kennington III7d6fa422021-02-08 17:04:02 -080015#include "net_sockio.h"
16
17#include <sys/socket.h>
18#include <unistd.h>
19
20namespace net
21{
22
23int SockIO::close()
24{
25 int ret = 0;
26 if (sockfd_ >= 0)
27 {
28 ret = ::close(sockfd_);
29 sockfd_ = -1;
30 }
31
32 return ret;
33}
34
35int SockIO::write(const void* buf, size_t len)
36{
37 return ::write(sockfd_, buf, len);
38}
39
40int SockIO::recv(void* buf, size_t maxlen)
41{
42 return ::recv(sockfd_, buf, maxlen, 0);
43}
44
45SockIO::~SockIO()
46{
47 SockIO::close();
48}
49
50} // namespace net