blob: 070d8c1a0e570a43a1de3d703b3dbf67c3ab4323 [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyev0eb70652014-02-27 18:35:07 -08007#include "unix-stream-factory.hpp"
Alexander Afanasyev7329e022014-02-27 14:47:22 -08008#include "core/global-io.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01009
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010010#include <boost/filesystem.hpp> // for canonical()
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010011
12namespace nfd {
13
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010014shared_ptr<UnixStreamChannel>
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080015UnixStreamFactory::create(const std::string& unixSocketPath)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010016{
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010017 boost::filesystem::path p(unixSocketPath);
18 p = boost::filesystem::canonical(p.parent_path()) / p.filename();
19 unix_stream::Endpoint endpoint(p.string());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010020
21 shared_ptr<UnixStreamChannel> channel = find(endpoint);
22 if (channel)
23 return channel;
24
Alexander Afanasyev7329e022014-02-27 14:47:22 -080025 channel = make_shared<UnixStreamChannel>(boost::ref(getGlobalIoService()),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010026 boost::cref(endpoint));
27 m_channels[endpoint] = channel;
28 return channel;
29}
30
31shared_ptr<UnixStreamChannel>
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080032UnixStreamFactory::find(const unix_stream::Endpoint& endpoint)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010033{
34 ChannelMap::iterator i = m_channels.find(endpoint);
35 if (i != m_channels.end())
36 return i->second;
37 else
38 return shared_ptr<UnixStreamChannel>();
39}
40
41} // namespace nfd