/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "common/wrapper.h"

#include <asio/ip/tcp.hpp>

using namespace ::hdfs;
using ::asio::ip::tcp;

tcp::socket * TcpConnection_create(IoServiceImpl *io_service) {
  tcp::socket *sock = new tcp::socket(io_service->io_service());
  return sock;
}

nullptr_t TcpConnection_connect(tcp::socket *self, std::string host, int port) {
  tcp::endpoint ep(asio::ip::address::from_string(host), static_cast<unsigned short>(port));
  asio::error_code ec;
  self->connect(ep, ec);
  //env->ReleaseStringUTFChars(jhost, host);
  if (!ec) {
    return nullptr;
  }
  assert (false);
}

void TcpConnection_disconnect(tcp::socket *self) {
  ::asio::error_code ec;
  self->close(ec);
  delete self;
}

void TcpConnection_destroy(tcp::socket *self) {
  if(self != NULL)  delete self;
}


