protected:
_Impl m_impl;
+ open_params_type m_openparam;
//socket_t m_socket;
socket_type create_socket(){
- socket_type sock = m_impl.create(open_params_type());
+ m_openparam = open_params_type();
+ socket_type sock = m_impl.create(m_openparam);
if ( sock == _Impl::invalid_handle )
throw socket_exception("roast::io::socket::create_socket(): Failed create new socket.");
m_handle = sock;
return sock;
}
- socket_type create_socket(int family, int socktype, int protocol){
- socket_type sock = m_impl.create(open_params_type(family, socktype, protocol));
+ socket_type create_socket(int family, int socktype, int protocol)
+ {
+ m_openparam = open_params_type(family, socktype, protocol);
+ socket_type sock = m_impl.create(m_openparam);
if ( sock == _Impl::invalid_handle )
throw socket_exception("roast::io::socket::create_socket(): Failed create new socket.");
m_handle = sock;
socket_(){ create_socket(); }
socket_(int family, int socktype, int protocol){ create_socket(family, socktype, protocol); }
//socket_(::FILE* fp) : _Base(fp){}
- socket_(const socket_& from) : _Base(from){}
+ socket_(const socket_& from) : _Base(from), m_openparam(from.m_openparam) {}
socket_(const char* host, int port) /*: _Base(open_params_type(host, port))*/{
create_socket();
open(host, port);
#define __SFJP_ROAST__windows__net__socket_impl_HPP__
#include "roast/io/socket/socket_base.hpp"
+#include <stdio.h> // sprintf
#include <string>
#include <ws2tcpip.h>
#include <Wspiapi.h>
int af;
int type;
int protocol;
+ const char* host;
+ int port;
open_params_type(){
+ host = NULL;
+ port = 0;
af = AF_INET;
type = SOCK_STREAM;
protocol = protocol;
}
open_params_type(int af_in, int type_in, int protocol_in){
+ host = NULL;
+ port = 0;
+ af = af_in;
+ type = type_in;
+ protocol = protocol_in;
+ }
+ open_params_type(const char* host_in, int port_in, int af_in, int type_in, int protocol_in){
+ host = host_in;
+ port = port_in;
af = af_in;
type = type_in;
protocol = protocol_in;
static void lasterr_assert(const char* msg){
nozero_assert(::WSAGetLastError(), msg);
}
+
+ // Private Classes
+ class addr
+ {
+ private:
+ ::addrinfo* data;
+ public:
+ addr(const char* host, int port, int af, int socktype) {
+ ::addrinfo hints;
+ ::memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = af;
+ hints.ai_family = socktype;
+
+#pragma warning(disable: 4996)
+ char port_str[12];
+ sprintf(port_str, "%d", port);
+#pragma warning(default: 4996)
+
+ nozero_assert(
+ ::getaddrinfo(host, port_str, &hints, &data),
+ "roast::windows::socket::addr() ::getaddrinfo() function was error.");
+
+ }
+ virtual ~addr(){
+ if ( data != NULL )
+ ::freeaddrinfo(data);
+ }
+ ///////////////
+ operator ::addrinfo* (){ return data; }
+ operator ::addrinfo* () const { return data; }
+ ::addrinfo* operator -> (){ return data; }
+ const ::addrinfo* operator -> () const { return data; }
+ };
public:
socket_impl(){}
lasterr_assert("roast::windows::socket::create() ::socket() function was error.");
return sock;
}
- static handler_type open(const open_params_type& params){
-
+ static handler_type open(handler_type handler, const open_params_type& params){
+ addr ai(params.host, params.port, params.af, params.type);
+ nozero_assert(
+ ::connect(handler, ai->ai_addr, ai->ai_addrlen),
+ "roast::socket::connect() ::connect() function was error.");
+ return handler;
}
static void close(handler_type handler)
{