#include "SDL_net.h"

#include "misc.h"
#include "globals.h"

#include <iostream>

using namespace std;

void send(string msg)
{
	int result;
	result=SDLNet_TCP_Send(sock, (char*)(msg+'\n').c_str(), msg.length()+1);
	if(result < msg.length()+1) {
		e("SDLNet_TCP_Send", SDLNet_GetError());
		// It may be good to disconnect sock because it is likely invalid now.
	}
	d("sent: ", msg);
}

// get a line, one char at a time
string getline()
{
	string msg;
	char a_char[0];
	int result;

	do
	{
		result=SDLNet_TCP_Recv(sock,a_char,1);
		if(result<=0)
			e("connection terminated", SDLNet_GetError());
		else
			msg += a_char[0];
	}
	while(result > 0 && a_char[0] != '\n');
	return msg;
}



