コード例 #1
0
ファイル: assoctab.c プロジェクト: talentlesshack/C2P2
main()
{
	int i;
	assoctab_t *pt[NTABS];

	for (i=0;i<NTABS;i++) {
		pt[i] = assoctab_create(sizeof(int));
		if (!pt[i]) {
			printf("create: test failed\n");
			exit(1);
		}
		if (assoctab_subscript(pt[i], 1) != NULL) {
			printf("subcript1: test failed\n");
			exit(1);
		}
	}
	for (i=0;i<NTABS;i++) {
		int h;
		h = _heapchk();
		if (h != _HEAPOK) {
			printf("heapchk: test failed\n");
			exit(1);
		}
		test1(pt[i], 1);
		test1(pt[i], 2);
		test1(pt[i], 3);
	}
	for (i=0;i<NTABS;i++) 
		assoctab_destroy(pt[i]);
	printf("test okay\n");
	return 0;
}
コード例 #2
0
ファイル: dppv.c プロジェクト: jleclanche/darkdust-ctp2
/*--------------------------------------------------------------------------
 Delete a particular player from the table.
--------------------------------------------------------------------------*/
dp_result_t pv_deletePlayer(pv_t *pv, int player)
{
	int i;
	pv_peer_t *peer;
	if (!pv) return dp_RES_BUG;

	DPRINT(("pv_deletePlayer(dp, %d)\n", player));

	/* Get this player's table. */
	peer = (pv_peer_t *)assoctab_subscript(pv->peers, player);
	if (!peer) {
		DPRINT(("pv_deletePlayer: no table for player %d\n", player));
		return dp_RES_EMPTY;
	}

	/* Free all memory pointed to by the variables in peer->vars */
	for (i=0; i < peer->vars->n_used; i++) {
		pv_var_t *pvar;
		assoctab_item_t *pe;
		pe = assoctab_getkey(peer->vars, i);
		if (!pe)
			break;	/* horrible error */
		pvar = (pv_var_t *) &pe->value;

		/* Destroy their values */
		if (pvar->buf) dp_FREE(pvar->buf);
	}
	if (peer->incoming.buf) dp_FREE(peer->incoming.buf);

	/* Destroy it, and remove it from the table. */
	assoctab_destroy(peer->vars);
	if (assoctab_subscript_delete(pv->peers, player))
		return dp_RES_BUG;
	return dp_RES_OK;
}
コード例 #3
0
ファイル: dppv.c プロジェクト: jleclanche/darkdust-ctp2
/*--------------------------------------------------------------------------
 Create a pv_t.
--------------------------------------------------------------------------*/
pv_t *pv_create(struct dp_s *dp)
{
	pv_t *pv;

	pv = (pv_t *)dp_MALLOC(sizeof(pv_t));
	if (!pv) return NULL;
	memset(pv, 0, sizeof(pv_t));

	pv->peers = assoctab_create(sizeof(pv_peer_t));

	if (!pv->peers) {
		assoctab_destroy(pv->peers);
		dp_FREE(pv);
		return NULL;
	}

	pv->next_send = dp->now;
	pv->cur_key_index = -1;
	pv->cur_ndests = 0;
	pv->new_ndests = 0;
	pv->cur_nkeys = 0;
	pv->cur_offset = 0;

	pv->dp = dp;
	return pv;
}
コード例 #4
0
ファイル: bhttp.c プロジェクト: jleclanche/darkdust-ctp2
/*------------------------------------------------------------------------
 Destroy an instance of the bhttp module.
------------------------------------------------------------------------*/
void bhttp_destroy(bhttp_t *bhttp)
{
	int i;

	if (!bhttp)
		return;
	close(bhttp->sockin);
	for (i = 0; i < bhttp->conns->n_used; i++) {
		assoctab_item_t *pi = assoctab_getkey(bhttp->conns, i);
		close(pi->key);
	}
	assoctab_destroy(bhttp->conns);
	memset(bhttp, 0, sizeof(bhttp_t));
	free(bhttp);
}
コード例 #5
0
ファイル: sbdserv.c プロジェクト: BygoneWorlds/anet
/*------------------------------------------------------------------------
 Destroy an instance of the sbdserv module.
------------------------------------------------------------------------*/
void sbdserv_destroy(sbdserv_t *sbdserv)
{
	int i;

	if (!sbdserv)
		return;
	close(sbdserv->sockin);
	for (i = 0; i < sbdserv->conns->n_used; i++) {
		assoctab_item_t *pi = assoctab_getkey(sbdserv->conns, i);
		close(pi->key);
	}	
	assoctab_destroy(sbdserv->conns);
	memset(sbdserv, 0, sizeof(sbdserv_t));
	free(sbdserv);
}
コード例 #6
0
ファイル: dppv.c プロジェクト: jleclanche/darkdust-ctp2
/*--------------------------------------------------------------------------
 Destroy a pv_t.
--------------------------------------------------------------------------*/
void pv_destroy(pv_t *pv)
{
	int i;
	if (!pv) return;

	/* For all players.  Step backwards to avoid having to move in delete. */
	for (i=pv->peers->n_used-1; i>=0; i--) {
		assoctab_item_t *pe;
		pe = assoctab_getkey(pv->peers, i);
		if (!pe)
			break;	/* horrible error */

		/* Delete this player */
		pv_deletePlayer(pv, pe->key);
	}
	/* Destroy the main table */
	assoctab_destroy(pv->peers);
}
コード例 #7
0
ファイル: trumpdll.c プロジェクト: jleclanche/darkdust-ctp2
int
commTerm(
	commTermReq_t *		req,		// Request (or NULL)
	commTermResp_t *	resp)		// Response (or NULL)
{
	commTermReq_t	reqDummy;
	commTermResp_t	respDummy;

	DPRINT(("@TRUMP commTerm(): "));

	if (req == NULL)
		req = (commTermReq_t *)memset(&reqDummy, 0, sizeof(*req));
	if (resp == NULL)
		resp = &respDummy;

	if (peertab) {
		int i;
		for (i=0; i<peertab->n_used; i++) {
			assoctab_item_t *pe = assoctab_getkey(peertab, i);
			if (!pe)
				DPRINT(("commTerm: couldn't find entry\n"));
			else if (pe->key != trump_HDL_ME) {
				DPRINT(("commTerm: closing handle %d\n", pe->key));
				tcpabi_udp_close(pe->key, UDP_CLOSE_NORMAL);
			} else {
				DPRINT(("commTerm: not closing handle %d\n", pe->key));
			}
		}
		assoctab_destroy(peertab);
	}
	free(scratch_flat);
	resp->status = comm_STATUS_OK;
	DPRINT(("commTerm: success\n"));

	//	unbind our endpoint and close open transport

	ShutDownUDP();

	return TRUE;
}
コード例 #8
0
ファイル: trumpdll.c プロジェクト: jleclanche/darkdust-ctp2
int
commInit(
	commInitReq_t *		req,		// Request (or NULL)
	commInitResp_t *	resp)		// Response (or NULL)
{
	commInitReq_t		reqDummy;
	commInitResp_t		respDummy;
	ip_adr_t adr_broadcast;
	ip_adr_t *padr;
	OSStatus			err;
	extern Str255	gSavedSelection;
//	DebugStr ( "\pcommInit()" );
	DPRINT(("@TRUMP commInit(): "));

	if (req == NULL)
		req = (commInitReq_t *)memset(&reqDummy, 0, sizeof(*req));
	if (resp == NULL)
		resp = &respDummy;

	scratch_flat = malloc(MAX_RAW_PKTLEN);
	//scratch_flat = my_dos_malloc(MAX_RAW_PKTLEN, &scratch_seg, &scratch_off, &scratch_selector);
	if (!scratch_flat) {
		DPRINT(("commInit: couldn't allocate DOS memory!\n"));
		resp->status = comm_STATUS_BAD;
		return FALSE;
	}

	//	check for the existanct of OpenTransport
	if(!OpenTransportExists() || !OpenTransportInetExists()) {
		//DebugStr("\pOpen Transport Does Not Exist");
		DPRINT(("commInit: UDP ABI not found\n"));
		resp->status = comm_STATUS_NETWORK_NOT_PRESENT;
		free(scratch_flat);
		return FALSE;
	}

	//	Initialize OpenTransport
	err = InitOpenTransport();
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		return FALSE;
	}

	//	initialize Internet Services

	gInetService = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		return FALSE;
	}

	//	open an endpoint for sending and recieving data

	err = CreateAndConfigUDP(&gUDPEndpoint);
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	//	create the peer table

	peertab = assoctab_create(sizeof(ip_adr_t));
	if (!peertab) {
		// ABORT! Out of Memory
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	//	Get information about the Internet

	err = OTInetGetInterfaceInfo(&gInetInfo, kDefaultInetInterface);
	if (err != noErr) {
		//DebugStr("\pCannot Get Information About Default Interface");
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	// Store our address in the peer table under the bogus ME handle
	padr = (ip_adr_t *)assoctab_subscript_grow(peertab, trump_HDL_ME);
	if (!padr) {
		DPRINT(("commInit: couldn't grow peer table\n"));
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		assoctab_destroy(peertab);

		ShutDownUDP();

		return FALSE;
	}
	dprint_peertab(peertab);
	DPRINT(("commInit: saving handle %d adr %x at %p\n", trump_HDL_ME, gInetInfo.fAddress, padr));
	memcpy(padr, &gInetInfo.fAddress, sizeof(ip_adr_t));
	dprint_peertab(peertab);

	// Open a handle good for receiving packets on the standard port
	// SRC = (*,*)
	// DEST = (localhost, pt->port)
	adr_broadcast = 0xffffffff;
	hdl_rx = trump_adr2hdl(adr_broadcast, SOCKET_MW2, SOCKET_MW2, TRUE);
	if (hdl_rx == trump_HDL_NONE) {
		DPRINT(("commInit: couldn't open handle for listening\n"));
		resp->status = comm_STATUS_BUSY;
		free(scratch_flat);
		assoctab_destroy(peertab);

		ShutDownUDP();

		return FALSE;
	}
	/*
	if ((req->flags & comm_INIT_FLAGS_RESUME) == 0) {
		if (!DoHostListDialog()) {
			resp->status = comm_STATUS_EMPTY;
			free(scratch_flat);
			assoctab_destroy(peertab);

			ShutDownUDP();

			return FALSE;
		}
	} else {

		//	we need to load the last string selected when we are resuming

		OpenPrefsFile();
		p2cstr(gSavedSelection);		//	the apps like C-strings
		ClosePrefsFile();

	}
	*/
	//	initialize our address list to nothing

	InitAddressList();

	//	add our own address to the beginning of the list (it MUST Be the first
	//	address in our list - we broadcast to all _other_ addresses in our list)

	AddAddressToList(gInetInfo.fAddress);

	//	add the address from the dialog to our broadcast list if the user chose one

	if (gSavedSelection[0] != 0) {
		InetHostInfo	theHostInfo;

		OTSetSynchronous(gInetService);
		err = OTInetStringToAddress(gInetService, gSavedSelection, &theHostInfo);
		OTSetAsynchronous(gInetService);

		if (err == noErr) {
			AddAddressToList(theHostInfo.addrs[0]);
		}
	}

	resp->status = comm_STATUS_OK;
	DPRINT(("commInit: success\n"));
	return TRUE;
}