Sha256: 7539b55570847a61f3801364108ef09907d11ae4cdacadc7f77db8569410737b

Contents?: true

Size: 1010 Bytes

Versions: 8

Compression:

Stored size: 1010 Bytes

Contents

#include "TcpComLink.h"
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>

//static local variables
struct TcpComLink
{
    int socket;
};

TcpComLink* TcpComLink_Create(int socket)
{
	TcpComLink* self = (TcpComLink*)malloc(sizeof(TcpComLink));
	memset(self, 0, sizeof(TcpComLink));
	self->socket = socket;
	return self;
}

void TcpComLink_Destroy(TcpComLink* self)
{
    free(self);
}


int TcpComLink_send(void * voidSelf, char * msg, int length)
{
	TcpComLink * self = (TcpComLink *)voidSelf;
    int total = 0;        // how many bytes we've sent
    int bytesleft = length; // how many we have left to send
    int n;

    while(total < length) {
        n = (int)send(self->socket, msg+total, bytesleft, 0);
        if (n == -1) { break; }
        total += n;
        bytesleft -= n;
    }

    return total;
} 


int TcpComLink_recv(void * voidSelf, char * buffer, int length)
{
	TcpComLink * self = (TcpComLink *)voidSelf;
	return (int)recv(self->socket, buffer, length,  MSG_WAITALL);
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
xcfit-0.9.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.8.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.7.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.6.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.5.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.4.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.3.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c
xcfit-0.2.0 XCFitDemo/Pods/cslim/src/Com/TcpComLink.c