Exemplo n.º 1
0
SendHelper_HandleWrite_res SendHelper_HandleWrite(bus *b, boxed_msg *box) {
    SSL *ssl = box->ssl;
    ssize_t wrsz = 0;

    /* Attempt a single write to the socket. */
    if (ssl == BUS_NO_SSL) {
        wrsz = write_plain(b, box);
    } else {
        assert(ssl);
        wrsz = write_ssl(b, box, ssl);
    }
    BUS_LOG_SNPRINTF(b, 5, LOG_SENDER, b->udata, 64,
        "wrote %zd", wrsz);

    if (wrsz == -1) {
        Send_HandleFailure(b, box, BUS_SEND_TX_FAILURE);
        return SHHW_ERROR;
    } else if (wrsz == 0) {
        /* If the OS set POLLOUT but we can't actually write, then
         * just go back to the poll() loop with no progress.
         * If we busywait on this, something is deeply wrong. */
        BUS_LOG_SNPRINTF(b, 1, LOG_SENDER, b->udata, 128,
            "suspicious: wrote %zd bytes to <fd:%d, seq_id%lld>",
            wrsz, box->fd, (long long)box->out_seq_id);
    } else {
        /* Update amount written so far */
        box->out_sent_size += wrsz;
    }

    size_t msg_size = box->out_msg_size;
    size_t sent_size = box->out_sent_size;
    size_t rem = msg_size - sent_size;

    BUS_LOG_SNPRINTF(b, 5, LOG_SENDER, b->udata, 64,
        "wrote %zd, rem is %zd", wrsz, rem);

    if (rem == 0) {             /* check if whole message is written */
        #ifndef TEST
        struct timeval done;
        #endif
        if (Util_Timestamp(&done, true)) {
            box->tv_send_done = done;
        } else {
            Send_HandleFailure(b, box, BUS_SEND_TIMESTAMP_ERROR);
            return SHHW_ERROR;
        }

        if (enqueue_EXPECT_message_to_listener(b, box)) {
            return SHHW_DONE;
        } else {
            Send_HandleFailure(b, box, BUS_SEND_TX_TIMEOUT_NOTIFYING_LISTENER);
            return SHHW_ERROR;
        }
    } else {
        return SHHW_OK;
    }
}
Exemplo n.º 2
0
void write_frame(int time) {
  if (rank != 0) {
    MPI_Send(u+1, nxl, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
  } else {
    int source, i, j, count, global_index;
    MPI_Status status;

    im = gdImageCreate(nx*PWIDTH,PHEIGHT);
    if (time == 0) {
      for (j=0; j<MAXCOLORS; j++)
	colors[j] = gdImageColorAllocate (im, j, 0, MAXCOLORS-j-1); 
      gdImageGifAnimBegin(im, file, 1, -1);
    } else {
      gdImagePaletteCopy(im, previm);
    }
    global_index = 0;
    for (source = 0; source < nprocs; source++) {
      if (source != 0) {
	MPI_Recv(buf, 1+nx/nprocs, MPI_DOUBLE, source, 0, MPI_COMM_WORLD,
		 &status);
	MPI_Get_count(&status, MPI_DOUBLE, &count);
      } else {
	for (i = 1; i <= nxl; i++) buf[i-1] = u[i];
	count = nxl;
      }
      for (i = 0; i < count; i++) {

	int color = (int)(buf[i]*MAXCOLORS/M);

	assert(color >= 0);
	if (color >= MAXCOLORS) color = MAXCOLORS-1;
	gdImageFilledRectangle
	  (im, global_index*PWIDTH, 0, (global_index+1)*PWIDTH-1,
	   PHEIGHT-1, colors[color]);
	global_index++;
      }
    }
    if (time == 0) {
      gdImageGifAnimAdd(im, file, 0, 0, 0, 0, gdDisposalNone, NULL);
    } else {
      gdImageGifAnimAdd(im, file, 0, 0, 0, 5, gdDisposalNone, previm);
      gdImageDestroy(previm);
    }
    previm=im;
    im=NULL;
  }
#ifdef DEBUG
  write_plain(time);
#endif
}
static void dot_end_graph(GVJ_t *job)
{
    graph_t *g = job->obj->u.g;
    Agiodisc_t* io_save;
    static Agiodisc_t io;

    if (io.afread == NULL) {
	io.afread = AgIoDisc.afread;
	io.putstr = (putstrfn)gvputs;
	io.flush = (flushfn)gvflush;
    }

    io_save = g->clos->disc.io;
    g->clos->disc.io = &io;
    switch (job->render.id) {
	case FORMAT_PLAIN:
	    write_plain(job, g, (FILE*)job, FALSE);
	    break;
	case FORMAT_PLAIN_EXT:
	    write_plain(job, g, (FILE*)job, TRUE);
	    break;
	case FORMAT_DOT:
	case FORMAT_CANON:
	    if (!(job->flags & OUTPUT_NOT_REQUIRED))
		agwrite(g, (FILE*)job);
	    break;
	case FORMAT_XDOT:
	case FORMAT_XDOT12:
	case FORMAT_XDOT14:
	    xdot_end_graph(g);
	    if (!(job->flags & OUTPUT_NOT_REQUIRED))
		agwrite(g, (FILE*)job);
	    break;
    }
    g->clos->disc.io = io_save;
}
Exemplo n.º 4
0
void dotneato_write(graph_t* g, std::string *output_str)
{
	double	xf, yf;
	char	*p;
	int	i;

	/* margins */
	if ((p = agget(g,"margin"))) {
		i = sscanf(p,"%lf,%lf",&xf,&yf);
		if (i > 0) g->u.drawing->margin.x = g->u.drawing->margin.y = POINTS(xf);
		if (i > 1) g->u.drawing->margin.y = POINTS(yf);
	}
	else {
		/* set default margins depending on format */
		switch (Output_lang) {
			case GIF:
			case PNG:
			case JPEG:
			case GD:
			case GD2:
			case ISMAP:
			case IMAP:
			case VRML:
			case SVG:
	        		g->u.drawing->margin.x = DEFAULT_EMBED_MARGIN_X;
				g->u.drawing->margin.y = DEFAULT_EMBED_MARGIN_Y;
				break;
			case POSTSCRIPT:
			case HPGL:
			case PCL:
			case MIF:
			case METAPOST:
			case FIG:
			case VTX:
			case ATTRIBUTED_DOT:
			case PLAIN:		
	        		g->u.drawing->margin.x = g->u.drawing->margin.y = DEFAULT_MARGIN;
				break;
			case CANONICAL_DOT:
				break;
		}
	}

	switch (Output_lang) {
		case POSTSCRIPT:
		case HPGL:
		case PCL:
		case MIF:
		case GIF:
		case PNG:
		case JPEG:
		case GD:
		case GD2:
		case ISMAP:
		case IMAP:
		case VRML:
		case METAPOST:
		case FIG:
		case SVG:
			/* output in breadth first graph walk order */
			emit_graph(g,0); break;
		case VTX:
			/* output sorted, i.e. all nodes then all edges */
			emit_graph(g,1); break;
		case ATTRIBUTED_DOT:
			attach_attrs(g);
			agwrite(g,Output_file); break;
		case CANONICAL_DOT:
			agwrite(g,Output_file); break;
		case PLAIN:
			attach_attrs(g);
			if (output_str)
			    write_plainstr(g,output_str);
			else
			    write_plain(g,Output_file);
			break;
	}
	fflush(Output_file);
}