ezsockets resynced to match our current version we're using for the server.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "global.h"
|
//#include "global.h"
|
||||||
|
//Commented out because there is no StepMania here.
|
||||||
|
|
||||||
/*******************************************
|
/*******************************************
|
||||||
ezsockets.cpp -- Header for sockets.cpp
|
ezsockets.cpp -- Header for sockets.cpp
|
||||||
Designed by Josh Allen and Charles
|
Designed by Josh Allen and Charles
|
||||||
@@ -14,10 +16,13 @@
|
|||||||
********************************************/
|
********************************************/
|
||||||
|
|
||||||
// We need the WinSock32 Library on Windows
|
// We need the WinSock32 Library on Windows
|
||||||
#ifdef _WINDOWS
|
#if defined(WIN32)
|
||||||
#pragma comment(lib,"wsock32.lib")
|
#pragma comment(lib,"wsock32.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>//REMOVE SOON
|
||||||
|
|
||||||
|
|
||||||
#include "ezsockets.h"
|
#include "ezsockets.h"
|
||||||
|
|
||||||
EzSockets::EzSockets()
|
EzSockets::EzSockets()
|
||||||
@@ -77,7 +82,10 @@ bool EzSockets::listen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// glibc already has socklen_t defined
|
// glibc already has socklen_t defined
|
||||||
#if !defined(LINUX)
|
// to whoever edited this:
|
||||||
|
// please do not assume LINUX is defined if you're compiling on linux!
|
||||||
|
// it will not compile properly.
|
||||||
|
#if defined(WIN32)
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -117,6 +125,42 @@ bool EzSockets::receiveLength( int &length ) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EzSockets::receive(char *data, int MAXlength)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
if ( !receiveLength(x))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int desc=1;
|
||||||
|
std::string outData;
|
||||||
|
char buf[4];
|
||||||
|
|
||||||
|
outData = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//YES! I know this is a crappy way to do it, but
|
||||||
|
//until someone tells me better... DON'T COMPLAIN
|
||||||
|
|
||||||
|
while ((outData.length()<x) && (desc>0)) {
|
||||||
|
desc = ::recv( sock, buf, 1 , 0 );
|
||||||
|
if (desc!=0)
|
||||||
|
outData+=buf[0];
|
||||||
|
}
|
||||||
|
if (desc==0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x>MAXlength)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy (data,outData.c_str(),x);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool EzSockets::receive( int &x )
|
bool EzSockets::receive( int &x )
|
||||||
{
|
{
|
||||||
if ( !receiveLength(x) )
|
if ( !receiveLength(x) )
|
||||||
@@ -282,6 +326,45 @@ bool EzSockets::connect( const std::string& host, unsigned short port )
|
|||||||
return desc >= 0;
|
return desc >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EzSockets::sendFlash (const std::string & inData)
|
||||||
|
{
|
||||||
|
int inDataSize = inData.length();
|
||||||
|
int desc = ::send( sock, inData.c_str(), inDataSize+1 , 0 );
|
||||||
|
//Over-ride the C-string by one.
|
||||||
|
if (desc)
|
||||||
|
return (true);
|
||||||
|
else
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string EzSockets::recvFlash ()
|
||||||
|
{
|
||||||
|
int desc=1;
|
||||||
|
std::string outData;
|
||||||
|
char buf[4];
|
||||||
|
|
||||||
|
outData = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//YES! I know this is a crappy way to do it, but
|
||||||
|
//until someone tells me better... DON'T COMPLAIN
|
||||||
|
|
||||||
|
buf[0] = '\r'; //Put something in buf to stop while.
|
||||||
|
while ((buf[0] != '\0') && (desc>0)) {
|
||||||
|
desc = ::recv( sock, buf, 1 , 0 );
|
||||||
|
if (desc!=0)
|
||||||
|
outData+=buf[0];
|
||||||
|
}
|
||||||
|
if (desc==0)
|
||||||
|
{
|
||||||
|
outData = "999Data Failure";
|
||||||
|
}
|
||||||
|
return outData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long EzSockets::uAddr()
|
long EzSockets::uAddr()
|
||||||
{
|
{
|
||||||
return addr.sin_addr.s_addr;
|
return addr.sin_addr.s_addr;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
Modified by Charles Lohr for use on
|
Modified by Charles Lohr for use on
|
||||||
windows and Unix.
|
windows and Unix.
|
||||||
|
Modified by Charles Lohr for use with
|
||||||
|
Macromedia Flash.
|
||||||
********************************************/
|
********************************************/
|
||||||
|
|
||||||
#ifndef __EZSOCKETS_H
|
#ifndef __EZSOCKETS_H
|
||||||
@@ -31,6 +33,8 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class EzSockets {
|
class EzSockets {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -64,6 +68,8 @@ class EzSockets {
|
|||||||
bool receive(std::vector<char> &data);
|
bool receive(std::vector<char> &data);
|
||||||
//Receive structure
|
//Receive structure
|
||||||
bool receive(int &x);
|
bool receive(int &x);
|
||||||
|
//Receive Structure (or other data)
|
||||||
|
int receive(char *data, int MAXlength);
|
||||||
//Send string
|
//Send string
|
||||||
bool send(const std::string& data);
|
bool send(const std::string& data);
|
||||||
//Send Structure (or other data)
|
//Send Structure (or other data)
|
||||||
@@ -74,6 +80,11 @@ class EzSockets {
|
|||||||
//NOTE: YOU MUST PUT IN IP, NOT NAME
|
//NOTE: YOU MUST PUT IN IP, NOT NAME
|
||||||
bool connect(const std::string& host, unsigned short port);
|
bool connect(const std::string& host, unsigned short port);
|
||||||
|
|
||||||
|
//Used for sending and receiving functions from flash
|
||||||
|
bool sendFlash (const std::string & inData);
|
||||||
|
|
||||||
|
std::string recvFlash ();
|
||||||
|
|
||||||
long uAddr();
|
long uAddr();
|
||||||
//Kill socket
|
//Kill socket
|
||||||
void close();
|
void close();
|
||||||
|
|||||||
Reference in New Issue
Block a user