Re: Syntax / Function callbacks

2023-09-11 Thread kevin


> On 11 Sep 2023, at 23:09, kevin@limping.ninja wrote:
> 
> void accept_callback()
> {
> object tmp= listener->accept();
> if (!tmp) return;
> object conn = Connection(tmp); 
> connections+=({conn});
> //destruct(tmp); <— this was disconnecting, but looking back at an old doc 
> from Hubbe, this was recommended as the Connection class insulation should 
> have already copied and owned the contents of this object; maybe this changed.
> }

Ignore me, the destruct works now with the inheritance as described, seems the 
changes I fiddled in trying to fix the “inherit Stdio.Port;” were the cause of 
all my grief and my code does indeed work exactly as it was back then but just 
changing that top level inherit to a variable.

LN

Re: Syntax / Function callbacks

2023-09-11 Thread kevin



> On 11 Sep 2023, at 19:16, will...@welliver.org wrote:
> Just to be clear, when you specify the accept callback to bind() it never 
> gets called when you make a connection? What version of pike are you using? 
> Are you returning -1 from main() so that the backend is running?
> 
> I've got lots of code that uses Stdio.Port and it's mostly unchanged from the 
> 7.2/7.6 era. I don't think I've ever used set_accept_callback(), mostly 
> because it's never seemed more convenient than doing it using bind().
> 
> I can confirm that Stdio.Port on 8.0.1738 does not have a definition for 
> set_accept_callback(), which is strange because (at least) the 7.8 SSL file 
> object uses it.
> 
> An example that I know works:
> 
> https://hg.sr.ht/~hww3/pikon/browse/Pikon.pmod/remote_access.pike?rev=tip
> 
> Bill


Thanks for the example, it was working too. My code had a -17 return on it so 
was staying open, but I was having a few different issues and got most of them 
sorted. I reverted back to old code where my connection object inherited 
Stdio.File instead and used socket::assign and socket::set_read_callback within 
the object. I had changed it while troubleshooting because of an issue with 
“inherit Stdio.Port;” at the program scope causing a fail; I changed that 
Stdio.Port inherit to a var.
The other issue was my original accept_callback would accept() to a temp object 
and then instantiate Connection with that object, add the connection object to 
an array and then destruct the temp object, when that happened it would kill 
the connection, but I’m pretty sure this code used to work that way.

void accept_callback()
{
object tmp= listener->accept();
if (!tmp) return;
object conn = Connection(tmp); 
connections+=({conn});
//destruct(tmp); <— this was disconnecting, but looking back at an old doc from 
Hubbe, this was recommended as the Connection class insulation should have 
already copied and owned the contents of this object; maybe this changed.
}

Either way, seems relatively sorted; it’s a bit messy so I’ll clean up what I 
was doing, but at least it’s working as expected now. 


Re: Syntax / Function callbacks

2023-09-11 Thread william

On 2023-09-11 11:35, kevin@limping.ninja wrote:

On 11 Sep 2023, at 17:29, Chris Angelico  wrote:

On Tue, 12 Sept 2023 at 01:25,  wrote:


The original state of the code had it using !bind(portnum, callbackfn) 
— those being actually port numbers and
the accept_callback function. But as noted, both bind and Stdio.Port 
instantiation with the callback silently
fail to execute the callback it seems. I get the connection, but the 
callback is never fired. At this point
I stripped everything back just simply trying to make a basic echo 
server. I forgot how much the documents

assert knowledge and forgot much of my own knowledge on Pike.


Just to be clear, when you specify the accept callback to bind() it 
never gets called when you make a connection? What version of pike are 
you using? Are you returning -1 from main() so that the backend is 
running?


I've got lots of code that uses Stdio.Port and it's mostly unchanged 
from the 7.2/7.6 era. I don't think I've ever used 
set_accept_callback(), mostly because it's never seemed more convenient 
than doing it using bind().


I can confirm that Stdio.Port on 8.0.1738 does not have a definition for 
set_accept_callback(), which is strange because (at least) the 7.8 SSL 
file object uses it.


An example that I know works:

https://hg.sr.ht/~hww3/pikon/browse/Pikon.pmod/remote_access.pike?rev=tip

Bill



Re: Syntax / Function callbacks

2023-09-11 Thread kevin



> On 11 Sep 2023, at 17:29, Chris Angelico  wrote:
> 
> On Tue, 12 Sept 2023 at 01:25,  wrote:
>> 
>> It should do: 
>> https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/_Stdio/_port/set_accept_callback.html
>> 
>> It exists within the documentation…? also Stdio.Port mainsock = 
>> Stdio.Port(, accept_callback) and  if (!mainsock->bind(, 
>> accept_callback)) both tend to silently allow the code to execute, but the 
>> callback is never executed non accept. So something is amiss.
>> 
> 
> Hmm, that's the internals. This is the public API:
> 
> https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/Stdio/Port.html
> 
> And it doesn't seem to be there. So maybe that's an omission in the
> pmod? Not sure.
> 
> ChrisA


The original state of the code had it using !bind(portnum, callbackfn) — those 
being actually port numbers and the accept_callback function. But as noted, 
both bind and Stdio.Port instantiation with the callback silently fail to 
execute the callback it seems. I get the connection, but the callback is never 
fired. At this point I stripped everything back just simply trying to make a 
basic echo server. I forgot how much the documents assert knowledge and forgot 
much of my own knowledge on Pike.

Re: Syntax / Function callbacks

2023-09-11 Thread Chris Angelico
On Tue, 12 Sept 2023 at 01:25,  wrote:
>
> It should do: 
> https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/_Stdio/_port/set_accept_callback.html
>
> It exists within the documentation…? also Stdio.Port mainsock = 
> Stdio.Port(, accept_callback) and  if (!mainsock->bind(, 
> accept_callback)) both tend to silently allow the code to execute, but the 
> callback is never executed non accept. So something is amiss.
>

Hmm, that's the internals. This is the public API:

https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/Stdio/Port.html

And it doesn't seem to be there. So maybe that's an omission in the
pmod? Not sure.

ChrisA


Re: Syntax / Function callbacks

2023-09-11 Thread kevin

> On 11 Sep 2023, at 17:18, Chris Angelico  wrote:
> 
> On Tue, 12 Sept 2023 at 01:14,  wrote:
>> 
>> int main() { … mainsock->set_accept_callback(accept_callback); ... }
>> 
>> Attempt to call the NULL-value
>> Unknown program: 0(/main()->accept_callback)
>> main.pike:53: /main()->main()
>> 
> 
> Looks like it's not a syntax problem, but that there's no
> set_accept_callback method. I don't know if that was ever a thing, but
> it isn't now. Are you able to initialize the Port with the callback
> already set?
> 
> Stdio.Port mainsock = Stdio.Port(12345, accept_callback);
> 
> ChrisA

It should do: 
https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/_Stdio/_port/set_accept_callback.html

It exists within the documentation…? also Stdio.Port mainsock = 
Stdio.Port(, accept_callback) and  if (!mainsock->bind(, 
accept_callback)) both tend to silently allow the code to execute, but the 
callback is never executed non accept. So something is amiss.




Re: Syntax / Function callbacks

2023-09-11 Thread Chris Angelico
On Tue, 12 Sept 2023 at 01:14,  wrote:
>
> int main() { … mainsock->set_accept_callback(accept_callback); ... }
>
> Attempt to call the NULL-value
> Unknown program: 0(/main()->accept_callback)
> main.pike:53: /main()->main()
>

Looks like it's not a syntax problem, but that there's no
set_accept_callback method. I don't know if that was ever a thing, but
it isn't now. Are you able to initialize the Port with the callback
already set?

Stdio.Port mainsock = Stdio.Port(12345, accept_callback);

ChrisA