Quote:
Originally Posted by ta0kira
Can you post a link to the code you're working with?
Kevin Barry
|
This is the non-blocking bit
Code:
* Need to change stdin to non-blocking. */
n = fcntl(0,F_GETFL);
if(n<0) {
fprintf(stderr,"Trouble getting stdin flags\n");
n = 0;
}
n = fcntl(0,F_SETFL,n|O_NONBLOCK);
if(n<0) {
fprintf(stderr,"Trouble setting stdin flags\n");
n = 0;
}
n = 0;
k = 1;
for(;;) {
char outbuf[1024];
char inbuf[1024];
if(n==0) {
n = read( 0, outbuf, 1024 );
if(n<0) {
if(errno == EAGAIN) {
usleep(10000);
n = 0;
}
else {
fprintf(stderr,"read n= %d err = %d\n",n,errno);
}
}
}
if(n>0) {
int rtn;
rtn = usb_bulk_write(usbhandle,0x02,outbuf,n-1,10);
if(rtn >= 0) n = 0;
fprintf(stderr,"usb_bulk_write %d\n",rtn);
}
if(k==0) {
int rtn;
rtn = usb_bulk_read(usbhandle,0x06,inbuf,1024,10);
if(rtn != -110) fprintf(stderr,"Got %d\n",rtn);
if(rtn>0) k = rtn;
}
if(k>0) {
fprintf(stdout,"usb read %d bytes\n",k);
/* TODO: Print them. */
k = 0;
}
}
Those function are defined in usb.h under the user... folder, right?
It also include this at the beginning #include <fcntl.h>