fwrite line buffering

2021-05-14 Thread Jernej Turnsek
Hi all,

while working with stdout fwrite function, I have noticed that line
buffering is not working. Is this by design or it is a bug?

Regards,
Jernej


Re: fwrite line buffering

2021-05-14 Thread Alan Carvalho de Assis
Hi Jernej,

Please define "not working"! :-)

Are you flushing it? Also "\n" at end of line forces it to be flushed.

BR,

Alan

On Friday, May 14, 2021, Jernej Turnsek  wrote:

> Hi all,
>
> while working with stdout fwrite function, I have noticed that line
> buffering is not working. Is this by design or it is a bug?
>
> Regards,
> Jernej
>


Re: fwrite line buffering

2021-05-14 Thread Johnny Billquist
I think his point was that it was implicitly flushed at every write, and 
not being buffered, but I might have misunderstood.


Anyway, I wouldn't expect fwrite to buffer on a per-line basis. fwrite 
is basically there for doing binary I/O. If you want something buffered, 
line oriented and user friendly, I would suggest printf.


  Johnny

On 2021-05-14 12:22, Alan Carvalho de Assis wrote:

Hi Jernej,

Please define "not working"! :-)

Are you flushing it? Also "\n" at end of line forces it to be flushed.

BR,

Alan

On Friday, May 14, 2021, Jernej Turnsek  wrote:


Hi all,

while working with stdout fwrite function, I have noticed that line
buffering is not working. Is this by design or it is a bug?

Regards,
Jernej





--
Johnny Billquist  || "I'm on a bus
  ||  on a psychedelic trip
email: b...@softjar.se ||  Reading murder books
pdp is alive! ||  tryin' to stay hip" - B. Idol


Re: fwrite line buffering

2021-05-14 Thread Jernej Turnsek
Hi Alan,

"\n" does not explicitly force the flush. I have configured the line
buffering which is actually working on printf and fputs, but not on fwrite.
I am using some application code that is running ok on Linux, but on Nuttx
it is not flushing properly. It flush only when the buffer is filled. I
hope I make myself clear now.

Jernej

On Fri, May 14, 2021 at 12:22 PM Alan Carvalho de Assis 
wrote:

> Hi Jernej,
>
> Please define "not working"! :-)
>
> Are you flushing it? Also "\n" at end of line forces it to be flushed.
>
> BR,
>
> Alan
>
> On Friday, May 14, 2021, Jernej Turnsek  wrote:
>
> > Hi all,
> >
> > while working with stdout fwrite function, I have noticed that line
> > buffering is not working. Is this by design or it is a bug?
> >
> > Regards,
> > Jernej
> >
>


devif_callback_alloc() not releasing callback structure?

2021-05-14 Thread Вадим Ястребов

Hello everyone!
 
I am still working on implementing 2 PHYs on IMXRT1064 and currently using 
netpkt example for transmitting the simplest packets.
 
Here is my problem:
 
Have 2 Ethernet interfaces (eth0 and eth1).
eth0 is UP, eth1 is DOWN.
Transmitting through eth1 results in packets coming out of interface that is UP 
(being eth0).
Expected behavior when transmitting through eth0.
 
eth0 is DOWN, eth1 is UP.
Transmitting through eth0 results in packets coming out of interface that is UP 
(being eth1).
Expected behavior when transmitting through eth1.
 
eth0 is UP, eth1 is UP.
Expected behavior when transmitting through eth0 and eth1.
 
When going through the code in devif_callback.c,
https://github.com/apache/incubator-nuttx/blob/3af0ef70ff5d5bd4d4d1cdb0152ee53182dc09dd/net/devif/devif_callback.c#L259-L270
I noticed an if condition which I am having difficulties understanding. The 
comment above it says something that, in my opinion, does not correspond to the 
code.
Shouldn’t line 266 be this one instead?
if (! netdev_verify (dev)  || ! (dev-> d_flags & IFF_UP))
 
Once I made that change, the packets stopped being sent through incorrect 
interfaces when the specified interface is DOWN.
However, now if I attempt to send packets with netpkt through an interface that 
is down multiple times (maybe 5-6? do not remember the precise number), at some 
point I will start getting ‘ERROR: Failed to allocate callback’ message. At 
this point, it doesn’t matter which interface I select, the error is always 
printed.
 
Then I noticed that line 270:
devif_callback_free ( NULL ,  NULL , list);
Will probably not do anything because the function checks the second argument 
for NULL right at the very beginning. This results in function not doing 
anything at all. Is that the expected behavior?
 
Please let me know your thoughts!
 
Regards,
Vadim Yastrebov
 
P.S. in  net/pkt/pkt_finddev.c
In function pkt_find_device(), originally, ‘eth0’ string was hardcoded when 
looking up the device. This prevented me from selecting the device for 
transmission. Instead, I used netdev_findbyindex() which now works just fine 
and is able to provide the correct device.