//
//  Wumbo-Socket.h
//  Wumbo
//
//  Created by Wade McGillis on 11/28/13.
//  Copyright (c) 2013 Wade McGillis. All rights reserved.
//

#ifndef __Wumbo_Socket_h__
#define __Wumbo_Socket_h__


#include <iostream>
#include "Wumbo-Header.h"
#if PLATFORM_APPLE
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
//#include <CFNetwork/CFNetwork.h>
//#include <SystemConfigu
#else
//#include <winsock.h>
#include <windows.h>
#include <WS2tcpip.h>
#endif
#include "Wumbo-Buffer.h"
/*
 fcntl(sockfd, F_SETFL, O_NONBLOCK);
 */
namespace Wumbo
{
	class TCPSocket
	{
	private:
		//
		int mysocket;
		struct addrinfo connectedSocketAddressInfo;
		//
		bool accepted;
		struct sockaddr acceptedSocketAddr;
		socklen_t acceptedSocketSize;
	public:
		TCPSocket(int sock, struct sockaddr info, int infosize);
		TCPSocket();
		void connect(char *address, unsigned int port);
		bool connected();
		void close();
		bool send(Wumbo::Buffer *buffer);
		Wumbo::Buffer *receive();
		const char* getipaddress();
	};
	
	class TCPListener
	{
	private:
		int listenSocket;
	public:
		void listen(unsigned int port);
		Wumbo::TCPSocket *accept();
		void close();
	};
};

#endif /* defined(__Wumbo__Wumbo_Socket__) */
