I have found the problem !! (FreeBASIC + Network)

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Hello!!

Previous subject : http://www.freebasic.net/forum/viewtopi ... =4&t=22469

I have simply Wiresharked my network (Windows XP - FreeBasic+MSCLIENT3.0) with my program who open a texte file on my network (File shared in windows xp)

When i open my file with my FreeBASIC program on drdos i have this
http://cpcdos.e-monsite.com/medias/images/cap-drdos.jpg
Image

and with freedos, with same FreeBASIC program, i have this
http://cpcdos.e-monsite.com/medias/imag ... reedos.jpg
Image

All programs and freebasic programs on DrDos work perfect !
he send "OPEN REQUEST" :D

But on FreeDos only freebasic programs does not work in network..
he send "CREATE NEW REQUEST" :(

Where are solutions ?
marcov
Posts: 3503
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by marcov »

There is a search before the create/open. Maybe FB checks file existence before creation, and that somehow goes wrong.

I would research that deeper.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Okay, keep me informed

Thank :-)
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Hi,

i tested the newest fb version, and this problem was not resolved :(
who is the main creator of fb ? i would contact with him :-)

Thank and good new year!
caseih
Posts: 2197
Joined: Feb 26, 2007 5:32

Re: I have found the problem !! (FreeBASIC + Network)

Post by caseih »

Why do you think this is a problem with FreeBASIC? By your own testing your compiled program works fine under DrDOS. So FreeBASIC is obviously generating a working executable. Would not the problem be in FreeDOS's networking stack?
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

I think this network problem is FREEBASIC because per example, i can edit files with interpreter or EDIT.COM of others programs on FreeDos, i not have problems, his send "OPEN REQUEST" on DrDos he send "OPEN REQUEST"

but when i would read of write file with a freebasic program on freedos, he send "CREATE NEW REQUEST"
on DrDos he send "OPEN REQUEST"

i think also it's a problem of SHARE.EXE, it's possible ?

i haven't read source code of open of fopen function

See FreeDos thread
http://t380712.emulators-freedos-develo ... 80712.html
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: I have found the problem !! (FreeBASIC + Network)

Post by dkl »

I don't know where the problem is, but maybe it can help to compare FreeBASIC vs. C ("pure" DJGPP) to see whether the problem is in FB.

Assuming you can still reproduce the issue with this FB test case:

Code: Select all

'' FreeBASIC test case
var f = freefile()
if open("C:\texte.txt", for binary, access read, as #f) <> 0 then
	print "FB open() failed"
	end 1
end if
close #f
Then this C code (to be compiled with DJGPP gcc) should show the same issue:

Code: Select all

/* Corresponding C test case */
#include <stdio.h>

int main(int argc, char** argv) {
	FILE *f = fopen("C:\\texte.txt", "rb");
	if (!f) {
		printf("fopen() failed\n");
		return 1;
	}
	fclose(f);
	return 0;
}
because FreeBASIC's "Open For Binary Access Read" will essentially just call DJGPP's fopen() with "rb" mode (read, binary - no write or create new). Of course this can be different for other FreeBASIC "Open" commands.

Also, remember that we've already seen that calling fopen() directly in FB instead of calling FB's own "Open" showed the same problem:
http://www.freebasic.net/forum/viewtopi ... 70#p197370

This suggests to me that the problem is not in FB's "Open", but rather in DJGPP or the system, but of course I can't be sure. It'd definitely be interesting to see test results of the plain C example.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Hi!

Thank you for your reply, i have connected my x: network driver and i have test your C code :

Code: Select all

/* Corresponding C test case */
#include <stdio.h>

int main(int argc, char** argv) {
    FILE *f = fopen("x:\\texte.txt", "rb");
    if (!f) {
        printf("fopen() failed\n");
        return 1;
    }
    fclose(f);
    return 0;
}
And this work! :D

Now how i can adapt my open function with this code ? i can use #define ? how i can correct this ?

Best regards!
caseih
Posts: 2197
Joined: Feb 26, 2007 5:32

Re: I have found the problem !! (FreeBASIC + Network)

Post by caseih »

Can you tell fbc to keep the .c file and compare the code it emits with the C example? Would be helpful in figuring out what FreeBASIC is doing. Frankly I'm surprise that the C code worked where the FB code didn't.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Hi,

this is c code with -gen gcc option :

Code: Select all

// Compilation of test.bas started at 09:12:10 on 01-04-2015

typedef   signed char       int8;
typedef unsigned char      uint8;
typedef   signed short      int16;
typedef unsigned short     uint16;
typedef   signed int        int32;
typedef unsigned int       uint32;
typedef   signed long long  int64;
typedef unsigned long long uint64;
typedef struct { char *data; int32 len; int32 size; } FBSTRING;
int32 fb_FileOpen( FBSTRING*, uint32, uint32, uint32, int32, int32 );
int32 fb_FileClose( int32 );
int32 fb_FileFree( void );
void fb_PrintString( int32, FBSTRING*, int32 );
FBSTRING* fb_StrAllocTempDescZEx( uint8*, int32 );
void fb_Init( int32, uint8**, int32 );
void fb_End( int32 );

int32 main( int32 __FB_ARGC__$0, char** __FB_ARGV__$0 )
{
	int32 fb$result$0;
	__builtin_memset( &fb$result$0, 0, 4 );
	fb_Init( __FB_ARGC__$0, (uint8**)__FB_ARGV__$0, 0 );
	label$0:;
	int32 F$0;
	int32 vr$1 = fb_FileFree(  );
	F$0 = vr$1;
	FBSTRING* vr$2 = fb_StrAllocTempDescZEx( (uint8*)"X:\x5Ctexte.txt", 12 );
	int32 vr$3 = fb_FileOpen( vr$2, 0u, 1u, 0u, F$0, 0 );
	if( vr$3 == 0 ) goto label$3;
	{
		FBSTRING* vr$5 = fb_StrAllocTempDescZEx( (uint8*)"FB open() failed", 16 );
		fb_PrintString( 0, vr$5, 1 );
		fb_End( 1 );
	}
	label$3:;
	label$2:;
	fb_FileClose( F$0 );
	label$1:;
	fb_End( 0 );
	return fb$result$0;
}

// Total compilation time: 5.017500370740891e-08 seconds.
origin :

Code: Select all

'' FreeBASIC test case
var f = freefile()
if open("C:\texte.txt", for binary, access read, as #f) <> 0 then
    print "FB open() failed"
    end 1
end if
close #f

i also confused, he use fb_FileOpen function.. but this is in crt?
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: I have found the problem !! (FreeBASIC + Network)

Post by dkl »

Just to be sure, does this FB code have the problem?

Code: Select all

var f = freefile()
if open("C:\texte.txt", for binary, access read, as #f) <> 0 then
    print "FB open() failed"
    end 1
end if
close #f
How about this?

Code: Select all

#include once "crt.bi"
var f = fopen("C:\texte.txt", "rb")
if f = 0 then
    print "CRT fopen() failed"
    end 1
end if
fclose(f)
(fb_FileOpen() is the implementation of the "Open" keyword - see fb_FileOpen() -> fb_FileOpenVfsEx() -> fb_DevFileOpen())
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

Hi!

i have test

Code: Select all

    var f = freefile()
    if open("X:\texte.txt", for binary, access read, as #f) <> 0 then
        print "FB open() failed"
        end 1
    end if
    close #f
and

Code: Select all

    #include once "crt.bi"
    var f = fopen("X:\texte.txt", "rb")
    if f = 0 then
        print "CRT fopen() failed"
        end 1
    end if
    fclose(f)
i have "CRT fopen() failed" retourned

and with your c code

Code: Select all

#include <stdio.h>

int main(int argc, char** argv) {
    FILE *f = fopen("x:\\texte.txt", "rb");
    if (!f) {
        printf("fopen() failed\n");
        return 1;
    }
    fclose(f);
compiled with

Code: Select all

gcc Fopen.c -o Fopen.exe
(gcc 4.7.3

And this work ! only the c code

i am confused! it's crasy!!
Last edited by Cpcdos on Jan 12, 2015 14:05, edited 1 time in total.
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

...

Post by DOS386 »

dkl wrote:Just to be sure, does this FB code have the problem?

Code: Select all

var f = freefile()
if open("C:\texte.txt", for binary, access read, as #f) <> 0 then
    print "FB open() failed"
    end 1
end if
close #f
NO. It works (compiled by FBC 1.01.1) perfectly in EDR-DOS and FreeDOS.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: I have found the problem !! (FreeBASIC + Network)

Post by Cpcdos »

This Isn't a local disk "c:\" but a network disk "x:\" the problem :/
Post Reply