YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
TcpStream.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2010 Anne van Rossum <anne@almende.com>
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <yarp/conf/system.h>
8#ifndef YARP_HAS_ACE
9
10
11// General files
12#include <sys/socket.h>
13#include <cstdio>
14
17
18using namespace yarp::os::impl;
19
20namespace {
21YARP_OS_LOG_COMPONENT(TCPSTREAM_POSIX, "yarp.os.impl.TcpStream.posix")
22}
23
24/* **************************************************************************************
25 * Implementation of TcpStream
26 * **************************************************************************************/
27
28TcpStream::TcpStream() = default;
29
30TcpStream::~TcpStream() = default;
31
32int TcpStream::open()
33{
34 set_handle(socket(AF_INET, SOCK_STREAM, 0));
35 if (get_handle() == -1) {
36 yCError(TCPSTREAM_POSIX, "At TcpStream::open there was an error: %d, %s", errno, strerror(errno));
37 return -1;
38 }
39 return 0;
40}
41
42int TcpStream::get_local_addr(sockaddr & sa)
43{
44 int len = sizeof(sa);
45 if (::getsockname(get_handle(), &sa, reinterpret_cast<socklen_t*>(&len)) == -1) {
46 return -1;
47 }
48 return 0;
49}
50
51int TcpStream::get_remote_addr (sockaddr & sa)
52{
53 int len = sizeof(sa);
54 if (::getpeername(get_handle(), &sa, reinterpret_cast<socklen_t*>(&len)) == -1) {
55 return -1;
56 }
57 return 0;
58}
59
60
61#endif
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
The components from which ports and connections are built.