-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
funopen: switch to using a thread behind a pipe() call so the FILE * …
…is a real stream ptr
- Loading branch information
1 parent
28e6255
commit d03d884
Showing
13 changed files
with
331 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "config.h" | ||
|
||
#include <stdlib.h> | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <errno.h> | ||
|
||
int myreadfn( void * cookie, char * buf, int nmem ) { | ||
static int num_read_total=0; | ||
if( num_read_total > 4096 ) { | ||
printf("myreadfn hit limit\n"); | ||
return 0; | ||
} | ||
int cookieasint = (int)cookie; | ||
printf("myreadfn with cookie(%d) asked for %d\n", cookieasint, nmem); | ||
for( int i = 0; i < nmem ; ++i ) { | ||
buf[i] = 'c'; | ||
} | ||
num_read_total += nmem; | ||
return nmem; | ||
} | ||
|
||
int mywritefn( void * cookie, char * buf, int nmem ) { | ||
int cookieasint = (int)cookie; | ||
printf("mywritefn with cookie(%d) asked for %d\n", cookieasint, nmem); | ||
for( int i = 0; i < nmem ; ++i ) { | ||
printf("%c\n", buf[i]); | ||
} | ||
return nmem; | ||
} | ||
|
||
int myclosefn( void * cookie ) { | ||
int cookieasint = (int)cookie; | ||
printf("myclosefn with cookie(%d)\n", cookieasint); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extern int myreadfn( void * cookie, char * buf, int nmem ); | ||
extern int mywritefn( void * cookie, char * buf, int nmem ); | ||
extern int myclosefn( void * cookie ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "config.h" | ||
|
||
#include <stdlib.h> | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <errno.h> | ||
|
||
#include <dicl_funopencommon.h> | ||
|
||
void dicl_funopenreadtest( char **argv ) | ||
{ | ||
printf("Beginning funopen read test\n"); | ||
|
||
void * thecookie = (void*)26; | ||
|
||
FILE * the_stream_ptr = funopen( thecookie, | ||
myreadfn, | ||
NULL, | ||
NULL, | ||
myclosefn ); | ||
|
||
if( errno ) { | ||
printf("Oops\n"); | ||
exit(2); | ||
} | ||
|
||
char result[2048]; | ||
int offset=0; | ||
int num_needed = 20; | ||
|
||
while( offset < num_needed ) { | ||
if( errno ) { | ||
printf("FORT (loopstart) errno is set %d\n", errno); | ||
} | ||
int num_this_round = 16; | ||
int num_actually_read = fread( result+offset, 1, num_this_round, the_stream_ptr); | ||
if( num_actually_read == 0 ) { | ||
printf("Nothing returned errno=%d\n", errno); | ||
exit (4); | ||
} | ||
printf("Read OK - have:\n"); | ||
for( int i = 0 ; i < num_this_round; ++i ) { | ||
printf("%c\n", *((char*)result+offset+i)); | ||
} | ||
offset+=num_this_round; | ||
if( errno ) { | ||
printf("FORT (loopend) errno is set %d\n", errno); | ||
} | ||
} | ||
if( errno ) { | ||
printf("FORT (end-1) errno is set %d\n", errno); | ||
} | ||
//printf("Calling fclose\n"); | ||
// fclose(the_stream_ptr); | ||
//printf("Called fclose\n"); | ||
if( errno ) { | ||
printf("FORT (end) errno is set %d\n", errno); | ||
} | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern void dicl_funopenreadtest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "config.h" | ||
|
||
#include <stdlib.h> | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include <errno.h> | ||
|
||
#include <dicl_funopencommon.h> | ||
|
||
void dicl_funopenwritetest( char **argv ) | ||
{ | ||
void * thecookie = (void*)26; | ||
|
||
if( errno ) { | ||
printf("Oops - errno set before call - it is %d\n", errno); | ||
exit(2); | ||
} | ||
|
||
FILE * the_stream_ptr = funopen( thecookie, | ||
NULL, | ||
mywritefn, | ||
NULL, | ||
myclosefn ); | ||
|
||
if( errno ) { | ||
printf("Oops - errno is %d\n", errno); | ||
exit(2); | ||
} | ||
|
||
char result[2048]; | ||
int offset=0; | ||
int num_needed = 32; | ||
for( int i = 0 ; i < num_needed ; ++i ) { | ||
result[i] = 'b'; | ||
} | ||
|
||
while( offset < num_needed ) { | ||
int num_this_round = 16; | ||
int num_actually_written = fwrite( result+offset, 1, num_this_round, the_stream_ptr); | ||
if( num_actually_written == 0 ) { | ||
printf("Nothing returned errno=%d\n", errno); | ||
exit (4); | ||
} | ||
printf("Write OK\n"); | ||
offset+=num_this_round; | ||
} | ||
fflush(the_stream_ptr); | ||
//fclose(the_stream_ptr); | ||
if( errno ) { | ||
printf("FOWT (end) errno is set %d\n", errno); | ||
} | ||
|
||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern void dicl_funopenwritetest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
AC_PREREQ(2.65) | ||
AC_INIT([libdicl], | ||
[0.1.31], | ||
[0.1.32], | ||
[[email protected]]) | ||
|
||
AC_SUBST(ACLOCAL_AMFLAGS, "-I macros") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ libdiclfunopen@PACKAGE_SUFFIX@_la_SOURCES= \ | |
|
||
libdiclfunopen@PACKAGE_SUFFIX@_la_LIBADD= \ | ||
libdicl@[email protected] \ | ||
-lnsl \ | ||
$(NULL) | ||
|
||
if LIBDICL_USING_GNULD | ||
|
Oops, something went wrong.