- gras_assert0(pd,"Please run gras_process_init on each process");
-
- for (port=startingPort ; port <= endingPort ; port++) {
- for (i=0; i<hd->portLen && hd->port[i] != port; i++);
- if (i<hd->portLen && hd->port[i] == port)
- continue;
-
- /* port not used so far. Do it */
- if (i == hd->portLen) {
- /* need to enlarge the tables */
- if (hd->portLen++) {
- hd->port2chan=(int*)realloc(hd->port2chan,hd->portLen*sizeof(int));
- hd->port =(int*)realloc(hd->port ,hd->portLen*sizeof(int));
- hd->raw =(int*)realloc(hd->raw ,hd->portLen*sizeof(int));
- } else {
- hd->port2chan=(int*)malloc(hd->portLen*sizeof(int));
- hd->port =(int*)malloc(hd->portLen*sizeof(int));
- hd->raw =(int*)malloc(hd->portLen*sizeof(int));
- }
- if (!hd->port2chan || !hd->port || !hd->raw) {
- fprintf(stderr,"GRAS: PANIC: A malloc error did lose all ports attribution on this host\n");
- hd->portLen = 0;
- return malloc_error;
- }
- }
- hd->port2chan[ i ]=raw ? pd->rawChan : pd->chan;
- hd->port[ i ]=port;
- hd->raw[ i ]=raw;
-
- /* Create the socket */
- if (!(*sock=(gras_sock_t*)malloc(sizeof(gras_sock_t)))) {
- fprintf(stderr,"GRAS: openServerSocket: out of memory\n");
- return malloc_error;
- }
+
+ sock->accepting = 0; /* no such nuisance in SG */
+
+ errcode = find_port(hd,port,&pr);
+ switch (errcode) {
+ case no_error: /* Port already used... */
+ RAISE2(mismatch_error,
+ "can't listen on address %s:%d: port already in use\n.",
+ host,port);
+
+ case mismatch_error: /* Port not used so far. Do it */
+ pr.tochan = sock->raw ? pd->rawChan : pd->chan;
+ pr.port = port;
+ pr.raw = sock->raw;
+ TRY(gras_dynar_push(hd->ports,&pr));