> On 11 Sep 2023, at 19:16, [email protected] 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. 

Reply via email to