<commit_before>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2015-2016 <NAME>

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Abaclade. If
not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#ifndef _ABACLADE_NET_TCP_HXX
#define _ABACLADE_NET_TCP_HXX

#ifndef _ABACLADE_HXX
   #error "Please #include <abaclade.hxx> before this file"
#endif
#ifdef ABC_CXX_PRAGMA_ONCE
   #pragma once
#endif

#include <abaclade/io/binary.hxx>
#include <abaclade/net/ip.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net {

//! Transmission Control Protocol-related classes and facilities.
namespace tcp {}

}} //namespace abc::net

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net { namespace tcp {

//! Initialized TCP connection.
class ABACLADE_SYM connection : public noncopyable {
public:
   /*! Constructor.

   @param fd
      Connected socket.
   @param addrRemote
      Address of the remote peer.
   @param portRemote
      Port of the remote peer.
   */
   connection(io::filedesc fd, ip::address && addrRemote, ip::port && portRemote);

   //! Destructor.
   ~connection();

   /*! Returns the address of the remote peer.

   @return
      IP address.
   */
   ip::address const & address() const {
      return m_addrRemote;
   }

   /*! Returns a binary reader/writer object representing the socket, to receive data from the
   remote peer.

   @return
      Reader/writer for the connection’s socket.
   */
   _std::shared_ptr<io::binary::file_readwriter> const & socket() {
      return m_bfrw;
   }

private:
   //! Reader/writer for the connection’s socket.
   _std::shared_ptr<io::binary::file_readwriter> m_bfrw;
   //! Address of the remote peer.
   ip::address m_addrRemote;
   //! Port of the remote peer.
   ip::port m_portRemote;
};

}}} //namespace abc::net::tcp

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net { namespace tcp {

/*! Attaches a coroutine scheduler to the current thread, and performs and necessary initialization
required for the current thread to run coroutines.<commit_msg>Rename abc::net::tcp::connection::address() and port() to remote_*()<commit_after>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2015-2016 <NAME>

This file is part of Abaclade.

Abaclade is free software: you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Abaclade is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Abaclade. If
not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#ifndef _ABACLADE_NET_TCP_HXX
#define _ABACLADE_NET_TCP_HXX

#ifndef _ABACLADE_HXX
   #error "Please #include <abaclade.hxx> before this file"
#endif
#ifdef ABC_CXX_PRAGMA_ONCE
   #pragma once
#endif

#include <abaclade/io/binary.hxx>
#include <abaclade/net/ip.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net {

//! Transmission Control Protocol-related classes and facilities.
namespace tcp {}

}} //namespace abc::net

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net { namespace tcp {

//! Initialized TCP connection.
class ABACLADE_SYM connection : public noncopyable {
public:
   /*! Constructor.

   @param fd
      Connected socket.
   @param addrRemote
      Address of the remote peer.
   @param portRemote
      Port of the remote peer.
   */
   connection(io::filedesc fd, ip::address && addrRemote, ip::port && portRemote);

   //! Destructor.
   ~connection();

   /*! Returns the address of the remote peer.

   @return
      IP address.
   */
   ip::address const & remote_address() const {
      return m_addrRemote;
   }

   /*! Returns the port the remote peer is using.

   @return
      Port.
   */
   ip::port const & remote_port() const {
      return m_portRemote;
   }

   /*! Returns a binary reader/writer object representing the socket, to receive data from the
   remote peer.

   @return
      Reader/writer for the connection’s socket.
   */
   _std::shared_ptr<io::binary::file_readwriter> const & socket() {
      return m_bfrw;
   }

private:
   //! Reader/writer for the connection’s socket.
   _std::shared_ptr<io::binary::file_readwriter> m_bfrw;
   //! Address of the remote peer.
   ip::address m_addrRemote;
   //! Port of the remote peer.
   ip::port m_portRemote;
};

}}} //namespace abc::net::tcp

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace abc { namespace net { namespace tcp {

/*! Attaches a coroutine scheduler to the current thread, and performs and necessary initialization
required for the current thread to run coroutines.
{'fraction_non_alphanumeric': 0.21169321727705698, 'fraction_numerical': 0.003613072754146822, 'mean_word_length': 2.107142857142857, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '215109', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1553, 'n_words': 598}