예제 #1
0
파일: speex_a.c 프로젝트: Kinglions/modizer
/*
  Write an Ogg page to a file pointer
  code from speexenc.c
*/
int oe_write_page(ogg_page *page, int fd)
{
  int written = 0;
  written += std_write(fd, page->header, page->header_len);
  written += std_write(fd, page->body,   page->body_len);

  return written;
}
bool cps_api_send_data(cps_api_channel_t handle, void *data, size_t len) {
    t_std_error rc = STD_ERR_OK;
    int by = std_write(handle,data,len,true,&rc);
    if (by != (int)len) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","Was not able to send the full message body.");
    }
    return (by==(int)len) ;
}
 bool cps_api_send_object(cps_api_channel_t handle, cps_api_object_t obj) {
    t_std_error rc = STD_ERR_OK;
    size_t len = cps_api_object_to_array_len(obj);
    int by = std_write(handle,cps_api_object_array(obj),len, true,&rc);
    if (by != (int)len) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","Was not able to send the full object.");
    }
    return (by==(int)len) ;
}
bool cps_api_send(cps_api_channel_t handle, cps_api_msg_operation_t op,
        const struct iovec *iov, size_t count) {

    cps_msg_hdr_t hdr;
    hdr.len =0;
    size_t ix = 0;
    for ( ; ix < count ; ++ix ) {
        hdr.len+=iov[ix].iov_len;
    }
    hdr.version = 0;
    hdr.operation = op;

    t_std_error rc = STD_ERR_OK;
    int by = std_write(handle,&hdr,sizeof(hdr),true,&rc);
    if (by!=sizeof(hdr)) return false;
    for ( ix = 0; ix < count ; ++ix ) {
        by = std_write(handle,iov[ix].iov_base,iov[ix].iov_len,true,&rc);
        if (by!=(int)iov[ix].iov_len) return false;
    }
    return true;
}
bool cps_api_send_header(cps_api_channel_t handle, uint32_t op,
        size_t len) {
    cps_msg_hdr_t hdr;
    hdr.len =len;
    hdr.operation = op;
    hdr.version = 0;
    t_std_error rc = STD_ERR_OK;
    int by = std_write(handle,&hdr,sizeof(hdr),true,&rc);
    if (by!=sizeof(hdr)) {
        EV_LOG(TRACE,DSAPI,0,"CPS IPC","Was not able to send the full message header.");
    }
    return (by==sizeof(hdr)) ;
}
예제 #6
0
파일: flac_a.c 프로젝트: ranvis/tina
static FLAC__StreamEncoderWriteStatus
flac_seekable_stream_encoder_write_callback(const FLAC__SeekableStreamEncoder *encoder,
				   const FLAC__byte buffer[],
				   unsigned bytes, unsigned samples,
				   unsigned current_frame, void *client_data)
{
  FLAC_ctx *ctx = (FLAC_ctx *)client_data;

  ctx->out_bytes += bytes;

  if (std_write(dpm.fd, buffer, bytes) == bytes)
    return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  else
    return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
}
예제 #7
0
파일: raw_a.c 프로젝트: Distrotech/TiMidity
static int output_data(char *buf, int32 bytes)
{
    int n;

    if(dpm.fd == -1)
      return -1;

    while(((n = std_write(dpm.fd, buf, bytes)) == -1) && errno == EINTR)
	;
    if(n == -1)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		  dpm.name, strerror(errno));
	return -1;
    }
    return n;
}
예제 #8
0
int main(int argc, char**argv) {
    char * path = "/var/run/ar.npu.shell";

    int opt = -1;
    char unit_str[30]="";
    char cmd_str[1024]="";
    char *exit_cmd="\n::exit\n";
    char *prompt_off="\n::prompt:off\n";
    char *prompt_on="\n::prompt:on\n";

    while ((opt=getopt(argc,argv,"u:c:"))!=-1) {
        switch(opt) {
        case 'u':
            snprintf(unit_str,sizeof(unit_str)-1,"::%s\n",optarg);
            break;
        case 'c':
            snprintf(cmd_str,sizeof(cmd_str)-1,"\n\n%s\n",optarg);
            break;
        default:
            printf("Valid args are [ -u unit -c \"cmd\" ]\n");
            exit (1);
        }
    }

    int sock=-1;

    if (std_cmd_redir_connect(path,&sock)!=STD_ERR_OK)
        return -1;
    if (strlen(cmd_str)>0) {
        int rc = std_write(sock,prompt_off,strlen(prompt_off)+1,true,NULL);
        if (rc==-1) return -1;
    } else {
        int rc = std_write(sock,prompt_on,strlen(prompt_on)+1,true,NULL);
        if (rc==-1) return -1;
        printf("Welcome to the NPU Shell\ntype ::exit to exit the shell and ::[npu] to change the default npu\n");
    }
    if (strlen(unit_str)>0) {
        int rc = std_write(sock,unit_str,strlen(unit_str)+1,true,NULL);
        if (rc==-1) return -1;
    }
    if (strlen(cmd_str)>0) {
        int rc = std_write(sock,cmd_str,strlen(cmd_str)+1,true,NULL);
        if (rc==-1) return -1;
    }

    while (true) {
        fflush(stdout);
        struct timeval tv={1,0};
        fd_set rset;
        int selfds[]={STDIN_FILENO,sock};
        int max_fd = -1;
        std_sel_adds_set(selfds,sizeof(selfds)/sizeof(*selfds),
                    &rset,&max_fd,true);

         int rc = std_select_ignore_intr(max_fd+1,&rset,NULL,NULL,&tv,NULL);

        if (rc==0) {
            if (strlen(cmd_str)>0) {
                int rc = std_write(sock,exit_cmd,strlen(exit_cmd)+1,true,NULL);
                if (rc==-1) return -1;
             }
             continue;
        }
        if (rc==-1) break;
        if (FD_ISSET(STDIN_FILENO,&rset)) {
            if ((rc=std_fd_copy(sock,STDIN_FILENO,NULL))==-1 || rc==0) break;
        }
        if (FD_ISSET(sock,&rset)) {
            if ((rc=std_fd_copy(STDOUT_FILENO,sock,NULL))==-1 || rc==0) break;
            fflush(stdout);
        }
    }
    return 0;
}