> I am trying to understand what triggers the Csrc.Read(buf) to return The Read call will eventually turn into a read() system call. For TCP it will return as long as there is at least one byte in the kernel's receive buffer for this connection, or if the buffer give to read() is filled up, or the connection is closed.
Do you know about ReadAtLeast? Read its documentation: go doc io.ReadAtLeast For example the following code will return exactly 32k bytes or return with an error. buf := make([]byte, 32*1024) ... n, err := io.ReadAtleast(Csrc, buf, len(buf)) .... I am guessing this may be what you want but your requirements are rather vague so I'm not sure. It'll help if you can show us some pseudo code that precisely describes what you expect to happen, possibly with pre and post conditions (but if ReadAtLeast is what you want, don't bother!). > On Dec 29, 2019, at 7:20 AM, Ron Wahler <ron.wah...@gmail.com> wrote: > > Jake, > > Thanks for the reply. Csrc.Read is what I was referring to as the connection > standard read, should not have used the words "standard read" sorry about > that. The problem I am trying to solve is reading an unknown amount of byte > data. I am trying to understand what triggers the Csrc.Read(buf) to return > when I send say 3 bytes to it with a client, I also keep the connection open > and send a few bytes of characters with the netcat tool, the Csrc.Read > returns, but the snip it below that with ReadAll does not return. I am trying > to understand the underlying behavior of what triggers a return with the data > in these two calls ? > > on this read : > > Csrc net.Conn > > buf := make([]byte, 1024*32) > > // READ FROM CLIENT > > > nBytes, err := Csrc.Read(buf) > > > > Csrc.Read(buf) returns with a few bytes that I send to it. It does not wait > for the entire allocated buf size to return. This works great, but I am > looking for a way to not preallocate a large buffer. > > > > I am prototyping with ReadAll, see the following snip it, but when I send a > few bytes to this call with a client, it does not return. The documentation > is saying it may be looking for an EOF which I do not send. > > > > > buf, read_err := ioutil.ReadAll(Csrc) > > > thanks, > Ron > > > > > > On Friday, December 27, 2019 at 5:11:42 PM UTC-7, Ron Wahler wrote: > I am looking for a net.conn standard read that would return a data buffer the > exact size of the read. I am trying to read an unknown amount of byte data > from the connection. With the read i am using I am required to pre-allocate a > buffer and pass that buffer to the read. I am looking for a read that works > more like the ReadString , but is for a byte slice. > > // I want something similar to this read that returns the read string into > the message string. > message, err := bufio.NewReader(ServerConn).ReadString('\n') > > if ( err != nil ){ > > fmt.Println("RELAY: ERROR: Reg Message read err:", > err) > > return > > } > > > > > > // had to preallocate a buffer, but I want a read to return me a buffer so I > don't have to guess how big to make it. > > > buf := make([]byte, 1024*32) > > // READ FROM CLIENT > > > nBytes, err := Csrc.Read(buf) > > > > > > Is this not possible, I have not seen any examples that would indicate that > there is a standard library that would do something like what I am looking > for. > > > > thanks, > > Ron > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/cd1f26d6-72aa-4239-83f2-18dc6220c2db%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/cd1f26d6-72aa-4239-83f2-18dc6220c2db%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/E2A1F28A-E0C1-40EA-AE53-90220F9F68E8%40bitblocks.com.