mIRC Home    About    Download    Register    News    Help

Print Thread
#262425 30/01/18 03:02 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Can we get a command that will peek into the sock-read buffer and return the buffered data without removing the data from the sockread buffer?

I'm currently working on an httpd and at times I need to see "whats next" before deciding what to do with the current data.

For example, HTTP headers can be folded(split into multiple lines) by following a linebreak(\r\n) with whitespace characters(tab or space):

<code>Header-Name: This is[\r\n]
a valid header[\r\n]</code>

After reading the header with /sockread -n &bvar, I'd like to be able to 'peek' into the read buffer to see if its followed by a whitespace character


Code:
/sockpeek [-fn] [numbytes] <%var|&binvar>
;; Functions the same as /sockread but does not
;; remove the bytes from the read buffer


Last edited by FroggieDaFrog; 30/01/18 03:04 AM.

I am SReject
My Stuff
FroggieDaFrog #262431 30/01/18 10:38 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
I'm not a big fan of this suggestion, this is typically something you should be scripting yourself, just stored the line read, read the next line and then deal with both lines.
This would not solve the problem of having to store state for when the data is not immediately available (sockreading multiple time in the same event)
It would mean mIRC would have to read the line from winsock and temp store it for you, effectively meaning that /sockread would have to check if there is something to read from a different buffer before processing the rq buffer, it would add extra processing for socket for everyone's code when you should be the one temp storing the data you want, this would just slow down the processing of socket in general, and while it's not so bad of suggestion in itself, I don't think a lot of people would actually use this, sorry I just hate this idea!
And would it fill $sockbr and $sockerr etc? There are more things to figure out than just adding a new command here, I think.

In the meantime I'm sure you know about this but your concrete example is trivial to solve:

Code:
on *:sockread:name:{
  if (%state == 0) {
    sockread -n &header
    if (!$sockbr) return
    sockread -n &header1
    if (!$sockbr) {
     hadd -mb table item &header
     set %state 1
     return
    }
    ;deal with &header and &header1
  }
  elseif (%state == 1) {
    sockread -n &header1
    if (!$sockbr) return
    noop $hget(table,item,&header)
    set %state 0
    ;deal with &header and &header1
  }
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #262432 30/01/18 11:22 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Originally Posted By: Wims
It would mean mIRC would have to read the line from winsock and temp store it for you

This is not how winsock works. You provide winsock with a buffer pointer when the socket descripter is created, and as data comes in, winsock adds the data to the buffer. There is no copying from a winsock buffer into an application buffer or such.

Now lets says that above is incorrect and you provide a buffer with each read. You have failed to account for mIRC already keeping a buffer. For example if there isn't a $crlf in the buffer, '/sockread %data' keeps data in the buffer even though mIRC would have had to read data from winsock to check for $crlf in the first place

Originally Posted By: Wims
And would it fill $sockbr and $sockerr etc?
Yes, to both. The only difference between the suggested /sockpeek and /sockread is that after mIRC extracts the 'read bytes' from the buffer, it would not remove those bytes from the buffer

Last edited by FroggieDaFrog; 30/01/18 11:35 AM.

I am SReject
My Stuff
FroggieDaFrog #262433 30/01/18 11:57 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
mIRC already keeping a buffer is what I'm talking about, I doubt the 'buffer pointer' filled by winsock is the same buffer that 'we' read from but I don't know exactly about the implementation there. Like I said it's not a bad idea in itself but that may just add complication to the current implementation for something that is not needed, that is, you can script it. In the meantime there are dozen of suggestions which can't be done by scripting, though, certainly, it's not what should matter or what should prevent you from making suggestions.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard