Beispiel #1
0
local int arenas_get_names(DBT *key, DBT *val)
{
    arenas_info *i;
    if (key->size == sizeof(struct player_record_key))
    {
        struct player_record_key *k = key->data;
        if (!(i = HashGetOne(arenas_hash, k->arenagrp)))
            HashAdd(arenas_hash, k->arenagrp, i = amalloc(sizeof(*i)));
        i->precs++;
        i->pbytes += key->size + val->size;
    }
    else if (key->size == sizeof(struct arena_record_key))
    {
        struct arena_record_key *k = key->data;
        if (!(i = HashGetOne(arenas_hash, k->arena)))
            HashAdd(arenas_hash, k->arena, i = amalloc(sizeof(*i)));
        i->arecs++;
        i->abytes += key->size + val->size;
    }
    else if (key->size == sizeof(struct current_serial_record_key))
    {
        struct current_serial_record_key *k = key->data;
        if (!(i = HashGetOne(arenas_hash, k->arenagrp)))
            HashAdd(arenas_hash, k->arenagrp, i = amalloc(sizeof(*i)));
        i->srecs++;
        i->sbytes += key->size + val->size;
    }
    else
        printf("unknown key type: length %d bytes\n", key->size);

    return FALSE;
}
static void* pmalloc(struct pool* p,size_t n) {
  void* x;
  if (n>p->rest) {
    if (n>4096) return amalloc(&p->a,n);
    if (!(p->dat=amalloc(&p->a,p->rest=16*1024))) return 0;
  }
  x=p->dat;
  p->dat+=n;
  p->rest-=n;
  return x;
}
Beispiel #3
0
static void alloc_ubuf_ildg(int my_rank)
{
   if (my_rank==0)
   {
      ubuf=amalloc(8*sizeof(su3_dble),4);
      vbuf=ubuf+4;
      vbuf_s=amalloc(4*sizeof(su3),4);
   }
   else
      ubuf=amalloc(4*sizeof(su3_dble),4);

   error(ubuf==NULL,1,"alloc_ubuf [archive_ildg.c]",
         "Unable to allocate auxiliary array");
}
Beispiel #4
0
int arcp_region_init_weakref(struct arcp_region *region) {
	struct arcp_weakref *stub;
	struct arcp_weakref *nostub;

	if (region == NULL) {
		return 0;
	}
	/* load current weakref */
	nostub =
		(struct arcp_weakref *) ak_load(&region->weakref, mo_consume);
	if (nostub != NULL) {
		/* weakref has already been initialized */
		return 0;
	}
	/* allocate a new weakref */
	stub = amalloc(sizeof(struct arcp_weakref));
	if (stub == NULL) {
		return -1;
	}
	/* initialize the weakref */
	ak_init(&stub->target, region);
	/* storecount 1 (the region), usecount 0 */
	ak_init(&stub->refcount, __ARCP_REFCOUNT_INIT(1, 0));
	stub->destroy = (arcp_destroy_f) __arcp_destroy_weakref;
	ak_init(&stub->weakref, NULL);
	if (unlikely(!ak_cas(&region->weakref, &nostub, stub,
			     mo_acq_rel, mo_relaxed))) {
		/* someone else set the weakref */
		afree(stub, sizeof(struct arcp_weakref));
	}
	return 0;
}
Beispiel #5
0
static void su3_appl_twist(su3_dble *u,double phase){
   double c,s;
   su3_dble *r;
   r=amalloc(sizeof(su3_dble),3);
   c = (double)cos(phase);
   s = (double)sin(phase);
   (*(r)).c11.re=c*(*(u)).c11.re-s*(*(u)).c11.im; 
   (*(r)).c11.im=s*(*(u)).c11.re+c*(*(u)).c11.im; 
   (*(r)).c12.re=c*(*(u)).c12.re-s*(*(u)).c12.im; 
   (*(r)).c12.im=s*(*(u)).c12.re+c*(*(u)).c12.im; 
   (*(r)).c13.re=c*(*(u)).c13.re-s*(*(u)).c13.im; 
   (*(r)).c13.im=s*(*(u)).c13.re+c*(*(u)).c13.im; 
   (*(r)).c21.re=c*(*(u)).c21.re-s*(*(u)).c21.im; 
   (*(r)).c21.im=s*(*(u)).c21.re+c*(*(u)).c21.im; 
   (*(r)).c22.re=c*(*(u)).c22.re-s*(*(u)).c22.im; 
   (*(r)).c22.im=s*(*(u)).c22.re+c*(*(u)).c22.im; 
   (*(r)).c23.re=c*(*(u)).c23.re-s*(*(u)).c23.im; 
   (*(r)).c23.im=s*(*(u)).c23.re+c*(*(u)).c23.im; 
   (*(r)).c31.re=c*(*(u)).c31.re-s*(*(u)).c31.im; 
   (*(r)).c31.im=s*(*(u)).c31.re+c*(*(u)).c31.im; 
   (*(r)).c32.re=c*(*(u)).c32.re-s*(*(u)).c32.im; 
   (*(r)).c32.im=s*(*(u)).c32.re+c*(*(u)).c32.im; 
   (*(r)).c33.re=c*(*(u)).c33.re-s*(*(u)).c33.im; 
   (*(r)).c33.im=s*(*(u)).c33.re+c*(*(u)).c33.im;
   *u=*r;
   afree(r);
}
Beispiel #6
0
int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri)
{
    char *data;
    char *line[MAX_HEADERS];
    int lines, slen,i, whitespace=0, where=0,code;
    char *version=NULL, *resp_code=NULL, *message=NULL;

    if(http_data == NULL)
        return 0;

    /* make a local copy of the data, including 0 terminator */
    data = (char *)amalloc(len+1);
    memcpy(data, http_data, len);
    data[len] = 0;

    lines = split_headers(data, len, line);

    /* In this case, the first line contains:
     * VERSION RESPONSE_CODE MESSAGE, such as HTTP/1.0 200 OK
     */
    slen = strlen(line[0]);
    version = line[0];
    for(i=0; i < slen; i++) {
        if(line[0][i] == ' ') {
            line[0][i] = 0;
            whitespace = 1;
        } else if(whitespace) {
            whitespace = 0;
            where++;
            if(where == 1)
                resp_code = &line[0][i];
            else {
                message = &line[0][i];
                break;
            }
        }
    }

    if(version == NULL || resp_code == NULL || message == NULL) {
        free(data);
        return 0;
    }

    httpp_setvar(parser, HTTPP_VAR_ERROR_CODE, resp_code);
    code = atoi(resp_code);
    if(code < 200 || code >= 300) {
        httpp_setvar(parser, HTTPP_VAR_ERROR_MESSAGE, message);
    }

    httpp_setvar(parser, HTTPP_VAR_URI, uri);
    httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "NONE");

    parse_headers(parser, line, lines);

    free(data);

    return 1;
}
Beispiel #7
0
/* starts timer to handle periodmessages */
local void aaction(Arena *arena, int action)
{
	if (action == AA_DESTROY || action == AA_CONFCHANGED)
	{
		ml->CleanupTimer(msg_timer, arena, msg_cleanup);
	}

	if (action == AA_CREATE || action == AA_CONFCHANGED)
	{
		int i, c = 0;
		periodic_msgs *pm;

		pm = amalloc(sizeof(*pm));
		pm->count = 0;
		pm->arena = arena;

		for (i = 0; i < MAXMSGS; i++)
		{
			char key[32];
			const char *v;

			pm->msgs[i].msg = NULL;
			pm->msgs[i].interval = 0;

			snprintf(key, sizeof(key), "PeriodicMessage%d", i);

			v = cfg->GetStr(arena->cfg, "Misc", key);

			if (v)
			{
				char *next;
				int interval = strtol(v, &next, 0);
				if (next)
				{
					int initialdelay = strtol(next, &next, 0);
					if (next)
					{
						/* skip spaces */
						while (*next && isspace(*next)) next++;
						if (*next)
						{
							pm->msgs[i].initialdelay = initialdelay;
							pm->msgs[i].interval = interval;
							pm->msgs[i].msg = astrdup(next);
							c++;
						}
					}
				}
			}
		}

		if (c)
			ml->SetTimer(msg_timer, 6000, 6000, pm, arena);
		else
			afree(pm);
	}
}
Beispiel #8
0
local void Init(Player *p, int k)
{
	EncData *ed, **p_ed = PPDATA(p, enckey);

	pthread_mutex_lock(&mtx);
	if (!(ed = *p_ed)) ed = *p_ed = amalloc(sizeof(*ed));
	pthread_mutex_unlock(&mtx);

	do_init(ed, k);
}
Beispiel #9
0
struct astr *astr_alloc(size_t len) {
	struct astrstr *str;
	str = amalloc(sizeof(struct astrstr) + len + 1);
	if (str == NULL) {
		return NULL;
	}

	astr_init(str, 0, str->data_start, __astr_destroystr);
	return str;
}
Beispiel #10
0
main()
{
      static char init_d[8] = { 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF };
      int init_i = 0x1111;
      double *a   = amalloc( sizeof(double), init_d, 1, 4 );
      double **b  = amalloc( sizeof(double), init_d, 2, 4, 5 );
      double ***c = amalloc( sizeof(double), init_d, 3, 4, 5, 6 );
      int ***d = amalloc( sizeof(int), &init_i, 3, 4, 5, 6 );
      int i, j, k;

      for (i = 0; i < 4; i++)
            for (j = 0; j < 5; j++ )
                  for (k = 0; k < 6; k++ )
                        d[i][j][k] = (i * 256) + (j * 16) + k;

      a = a, b = b, c = c;

      return 0;
}
Beispiel #11
0
struct asf_print_instance *asf_print_new(void/*lock*/)
{
    struct asf_print_instance *handle;
    handle = amalloc(sizeof(struct asf_print_instance));
    if (handle) {
        handle->print_ctrl_list = NULL;
        handle->valid = ASF_PRINT_VALID_MAGIC_NUM;
    }
    return handle;
}
Beispiel #12
0
struct astr *astr_create(size_t len, char *data) {
	struct astr *str;
	str = amalloc(sizeof(struct astr));
	if (str == NULL) {
		return NULL;
	}

	astr_init(str, len, data, __astr_destroy);
	return str;
}
Beispiel #13
0
local void aaction_work(void *clos)
{
	Arena *arena = clos;
	LinkedList *dls = P_ARENA_DATA(arena, dlkey);
	struct MapDownloadData *data = NULL;
	char fname[256];

	/* first add the map itself */
	/* cfghelp: General:Map, arena, string
	 * The name of the level file for this arena. */
	if (mapdata->GetMapFilename(arena, fname, sizeof(fname), NULL))
		data = compress_map(fname, TRUE);

	if (!data)
	{
		/* emergency hardcoded map: */
		byte emergencymap[] =
		{
			0x2a, 0x74, 0x69, 0x6e, 0x79, 0x6d, 0x61, 0x70,
			0x2e, 0x6c, 0x76, 0x6c, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x78, 0x9c, 0x63, 0x60, 0x60, 0x60, 0x04,
			0x00, 0x00, 0x05, 0x00, 0x02
		};

		lm->LogA(L_WARN, "mapnewsdl", arena, "can't load level file, falling back to tinymap.lvl");
		data = amalloc(sizeof(*data));
		data->checksum = 0x5643ef8a;
		data->uncmplen = 4;
		data->cmplen = sizeof(emergencymap);
		data->cmpmap  = amalloc(sizeof(emergencymap));
		memcpy(data->cmpmap, emergencymap, sizeof(emergencymap));
		astrncpy(data->filename, "tinymap.lvl", sizeof(data->filename));
	}

	LLAdd(dls, data);

	/* now look for lvzs */
	mapdata->EnumLVZFiles(arena, one_lvz_file, dls);

	aman->Unhold(arena);
}
Beispiel #14
0
Datei: ev.c Projekt: nexa/me
events_t *ev_create_events(size_t size) {
  events_t *evs;
  int i;

  if (size > EV_MAX_SIZE) return NULL;
  
  evs = amalloc(sizeof(events_t));
  if (evs == NULL) return NULL;
  evs->stop = 0;
  

}
Beispiel #15
0
void main(){
 double kappa;
 complex_dble **a,**b,**x; 
 int i,L[4],n[4];
 complex_dble kappa_c,f;
 full_spinor_dble A,B,X;

 X  = fsd0;
 a = amalloc(12*sizeof(*complex_dble));
 b = amalloc(12*sizeof(*complex_dble));
 c = amalloc(12*sizeof(*complex_dble));
 for (i=0;i<12;i++){
  a[i] = amalloc(12*sizeof(complex_dble));
  b[i] = amalloc(12*sizeof(complex_dble));
  x[i] = amalloc(12*sizeof(complex_dble));
 }

 n[0]=0;
 n[1]=0;
 n[2]=0;
 n[3]=0;
 B = unit_fsd(B);
 A = pspacedenom(kappa,L,n);
 fsd_to_mat(A,a);
 fsd_to_mat(B,b);
 fsd_to_mat(X,x);

 gaussj(a,12,b,12);  


}
Beispiel #16
0
local int RefreshNewsTxt(void *dummy)
{
	MMapData *mmd;
	uLong csize;
	byte *cnews;

	mmd = MapFile(cfg_newsfile, FALSE);

	if (!mmd)
	{
		lm->Log(L_WARN,"<mapnewsdl> news file '%s' not found in current directory", cfg_newsfile);
		goto done1;
	}

	/* don't read if it hasn't been modified */
	if (mmd->lastmod == newstime)
		goto done2;

	newstime = mmd->lastmod;
	csize = (uLong)(1.0011 * mmd->len + 35);

	/* calculate crc on mmap'd map */
	newschecksum = crc32(crc32(0, Z_NULL, 0), mmd->data, mmd->len);

	/* allocate space for compressed version */
	cnews = amalloc(csize);

	/* set up packet header */
	cnews[0] = S2C_INCOMINGFILE;
	/* 16 bytes of zero for the name */

	/* compress the stuff! */
	compress(cnews+17, &csize, mmd->data, mmd->len);

	/* shrink the allocated memory */
	cnews = realloc(cnews, csize+17);
	if (!cnews)
	{
		lm->Log(L_ERROR,"<mapnewsdl> realloc failed in RefreshNewsTxt");
		goto done2;
	}
	cmpnewssize = csize+17;

	if (cmpnews) afree(cmpnews);
	cmpnews = cnews;
	lm->Log(L_DRIVEL,"<mapnewsdl> news file '%s' reread", cfg_newsfile);

done2:
	UnmapFile(mmd);
done1:
	return TRUE;
}
Beispiel #17
0
local void Check(const char *name, const char *pwd,
		void (*done)(void *clos, int success), void *clos)
{
	char work[NAMELEN+PWLEN];
	check_state_t *st = amalloc(sizeof(*st));
	st->done = done;
	st->clos = clos;
	hash_password(name, pwd, st->given, work);
	persist->GetGeneric(
			KEY_PWCACHE,
			work, NAMELEN,
			st->expected, HASHLEN,
			check_done, st);
}
Beispiel #18
0
local int players_get_names(DBT *key, DBT *val)
{
    players_info *i;
    if (key->size == sizeof(struct player_record_key))
    {
        struct player_record_key *k = key->data;
        if (!(i = HashGetOne(players_hash, k->name)))
            HashAdd(players_hash, k->name, i = amalloc(sizeof(*i)));
        i->recs++;
        i->bytes += key->size + val->size;
    }

    return FALSE;
}
Beispiel #19
0
local void LoadData(Arena *arena)
{
	struct adata *ad = P_ARENA_DATA(arena, adkey);
	int i;
	
	ad->sectionList = LLAlloc();
	ad->warpSectionList = LLAlloc();
	
	for (i = 0; i < 8; i++)
	{
		struct WarpSection *warpSection = amalloc(sizeof(*warpSection));
		struct Section *section = amalloc(sizeof(*section));
		
		if (i < 4)
		{
			warpSection->in_x1 = i * 12 + 454;
			warpSection->in_y1 = 510;
			warpSection->in_x2 = i * 12 + 461;
			warpSection->in_y2 = 517;
		}
		else
		{
			warpSection->in_x1 = (i - 4) * 12 + 526;
			warpSection->in_y1 = 510;
			warpSection->in_x2 = (i - 4) * 12 + 533;
			warpSection->in_y2 = 517;
		}
		
		warpSection->out_x1 = section->x1 = i * 60 + 272;
		warpSection->out_y1 = section->y1 = 258;
		warpSection->out_x2 = section->x2 = i * 60 + 331;
		warpSection->out_y2 = section->y2 = 497;
		
		LLAdd(ad->sectionList, section);
		LLAdd(ad->warpSectionList, warpSection);
	}
}
Beispiel #20
0
void thread_initialize(void)
{
    thread_type *thread;

    /* set up logging */

#ifdef THREAD_DEBUG
    log_initialize();
    _logid = log_open("thread.log");
    log_set_level(_logid, THREAD_DEBUG);
#endif

#ifdef DEBUG_MUTEXES
    /* create all the internal mutexes, and initialize the mutex tree */

    _mutextree = avl_tree_new(_compare_mutexes, NULL);

    /* we have to create this one by hand, because there's no
    ** mutextree_mutex to lock yet!
    */
    _mutex_create(&_mutextree_mutex);

    _mutextree_mutex.mutex_id = _next_mutex_id++;
    avl_insert(_mutextree, (void *)&_mutextree_mutex);
#endif

    thread_mutex_create(&_threadtree_mutex);
    thread_mutex_create(&_library_mutex);

    /* initialize the thread tree and insert the main thread */

    _threadtree = avl_tree_new(_compare_threads, NULL);

    thread = (thread_type *)amalloc(sizeof(thread_type));

    thread->thread_id = _next_thread_id++;
    thread->line = 0;
    thread->file = strdup("main.c");
    thread->sys_thread = pthread_self();
    thread->create_time = time(NULL);
    thread->name = strdup("Main Thread");

    avl_insert(_threadtree, (void *)thread);

    _catch_signals();

    _initialized = 1;
}
Beispiel #21
0
/*
 * MemAlloc - get some memory
 */
ALLOCPTR MemAlloc( unsigned size )
{
ALLOCPTR        ptr;

        if( size == 0 ) return( NULL );
        ptr = amalloc( size );
        if( ptr != NULL ) {
            amemset( ptr, 0, size );
        } else {
            MessageBox( NULL, "Out Of Memory!", EditTitle,
                        MB_SYSTEMMODAL | MB_OK );
            exit( -1 );         /* panic situation */
        }
        return( ptr );

} /* MemAlloc */
Beispiel #22
0
local FlagTeam *CreateFlagTeam(Arena *a, int freq)
{
	DEF_AD(a);

	FlagTeam *team = amalloc(sizeof(FlagTeam));
	team->Arena = a;
	team->Freq = freq;
	team->DroppedFlags = 0;
	team->FlagSeconds = 0;
	team->Breakdown = HashAlloc();

	MYGLOCK;
	LLAdd(ad->FlagTeams, team);
	MYGUNLOCK;

	return team;
}
Beispiel #23
0
int aqueue_init(aqueue_t *aqueue) {
	struct aqueue_node *sentinel;
	/* allocate and initialize a sentinel node */
	sentinel = amalloc(sizeof(struct aqueue_node));
	if (sentinel == NULL) {
		return -1;
	}
	arcp_init(&sentinel->item, NULL);
	arcp_init(&sentinel->next, NULL);
	arcp_region_init(sentinel, (arcp_destroy_f) aqueue_node_destroy);

	/* set both head and tail to the sentinel */
	arcp_init(&aqueue->head, sentinel);
	arcp_init(&aqueue->tail, sentinel);
	arcp_release(sentinel);
	return 0;
}
Beispiel #24
0
local void FlagLost(Arena *a, Player *p, int fid, int how)
{
	DEF_AD(a);
	BDEF_PD(p);

	if(how == CLEANUP_DROPPED)
	{
		FlagOwner *owner = amalloc(sizeof(FlagOwner));
		owner->Arena = a;
		astrncpy(owner->Name, p->name, sizeof(p->name));
		owner->Freq = p->pkt.freq;
		owner->FlagID = fid;
		ad->FlagOwners[fid] = owner;

		pdat->DroppedFlags++;
		FlagTeam *team = GetFlagTeam(a, p->pkt.freq);
		team->DroppedFlags++;
	}
}
Beispiel #25
0
void httpp_set_query_param(http_parser_t *parser, const char *name, const char *value)
{
    http_var_t *var;

    if (name == NULL || value == NULL)
        return;

    var = (http_var_t *)amalloc(sizeof(http_var_t));

    var->name = strdup(name);
    var->value = url_escape(value);

    if (httpp_get_query_param(parser, name) == NULL) {
        avl_insert(parser->queryvars, (void *)var);
    } else {
        avl_delete(parser->queryvars, (void *)var, _free_vars);
        avl_insert(parser->queryvars, (void *)var);
    }
}
Beispiel #26
0
local void player_action(Player *p, int action, Arena *arena)
{
	PData *pdata = PPDATA(p, pdata_key);

	if (action == PA_CONNECT)
	{
		FormulaVariable *var = amalloc(sizeof(FormulaVariable));
		var->name = astrdup("me");
		var->type = VAR_TYPE_PLAYER;
		var->p = p;
		pdata->vars = HashAlloc();
		HashAdd(pdata->vars, var->name, var);
	}
	else if (action == PA_DISCONNECT)
	{
		HashEnum(pdata->vars, var_free_enum, NULL);
		HashFree(pdata->vars);
	}
}
Beispiel #27
0
local int UpdateScores(void *a)
{
	DEF_AD((Arena *)a);
	myPDType *pdata;

	for(int i = 0; i < MAXFLAGS; i++)
	{
		FlagOwner *owner = ad->FlagOwners[i];
		if(owner)
		{
			//lm->LogA(L_ERROR, "hs_flagtime", a, "owner of flag %d is %s", i, owner->Name);
			Player *p = pd->FindPlayer(owner->Name);
			if(p && p->pkt.freq == owner->Freq)
			{
				pdata = BPD(p);
				pdata->FlagSeconds++;
			}

			FlagTeam *team = GetFlagTeam(a, owner->Freq);
			team->FlagSeconds++;

			MYGLOCK;
			int *seconds = HashGetOne(team->Breakdown, owner->Name);
			if(seconds)
			{
				*seconds = *seconds + 1;
				HashReplace(team->Breakdown, owner->Name, seconds);
				//lm->LogA(L_ERROR, "hs_flagtime", a, "%s flag seconds: %d", owner->Name, *seconds);
			}
			else
			{
				seconds = amalloc(sizeof(*seconds));
				*seconds = 1;
				HashReplace(team->Breakdown, owner->Name, seconds);
				//lm->LogA(L_ERROR, "hs_flagtime", a, "%s new flag seconds: %d", owner->Name, *seconds);
			}
			MYGUNLOCK;

		}
	}
	return TRUE;
}
void *malloc_from_CAVE_memory(size_t size) {
#if defined(__irix)
  // Allocate memory from our shared memory arena
  if (shared_CAVE_memory_arena == NULL) {
     // this should be fun.
     msgErr << "Shared CAVE memory not allocated.  Prepare to crash and burn."
            << sendmsg;
     return NULL;
  } else {
    // get memory from the CAVE shared memory arena
    return amalloc(size, shared_CAVE_memory_arena); 
  }
#else
  // Allocate from shared CAVE pool
  void *retval = CAVEMalloc(size);
  if (!retval)
    // this should be fun.
    msgErr << "Not enough shared CAVE memory. Prepare to crash and burn."
           << sendmsg;
  return retval;
#endif
}
Beispiel #29
0
void getdel(int n)
{
	TreapHead *t = NULL;
	int i, avg, q, max, leaves;

	printf("adding nodes...\n");
	for (i = 0; i < n; i++)
	{
		TreapHead *n = amalloc(sizeof(*n));
		n->key = rand() % 10000;
		TrPut(&t, n);
	}

	for (;;)
	{
		char op;
		int key;

		printf("nodes:\n");
		TrEnum(t, print, NULL);

		printf("op key> ");
		scanf("%c %d", &op, &key);
		if (op == 'g')
		{
			TreapHead *n = TrGet(t, key);
			if (n)
				printf("found: key = %d\n", n->key);
			else
				printf("not found\n");
		}
		else if (op == 'd')
			afree(TrRemove(&t, key));
		else if (op == 'q')
			break;
	}
	TrEnum(t, tr_enum_afree, NULL);
}
Beispiel #30
0
static connection_t *_accept_connection(int duration)
{
    sock_t sock, serversock;
    char *ip;

    serversock = wait_for_serversock (duration);
    if (serversock == SOCK_ERROR)
        return NULL;

    /* malloc enough room for a full IP address (including ipv6) */
    ip = (char *)amalloc(MAX_ADDR_LEN);

    sock = sock_accept(serversock, ip, MAX_ADDR_LEN);
    if (sock == SOCK_ERROR) {
        free (ip);
        if (sock_recoverable(sock_error()))
            return NULL;

        WARN2("accept() failed with error %d: %s", sock_error(), strerror(sock_error()));
        thread_sleep (500000);
        return NULL;
    }

    connection_t *con = NULL;
    /* Make any IPv4 mapped IPv6 address look like a normal IPv4 address */
    if (strncmp (ip, "::ffff:", 7) == 0)
        memmove (ip, ip+7, strlen (ip+7)+1);

    if (accept_ip_address (ip)) {
        con = connection_create (sock, serversock, ip);
        if (con)
            return con;
    }
    sock_close (sock);
    free(ip);
    return NULL;
}