<commit_before>//
// Copyright © 2011 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package stomp

import (
	"fmt"
	"io"
	"os"
	"time"
)

// Network writer
func (c *Connection) writer() {
	q := false
	for {

		select {
		case d := <-c.output:
			c.wireWrite(d)
		case q = <-c.wsd:
			break
		}

		if q {
			break
		}

	}

}

// Wiredata write
func (c *Connection) wireWrite(d wiredata) {
	f := d.frame
	switch f.Command {
	case "\n": // HeartBeat frame
		if _, e := fmt.Fprintf(c.wtr, "%s", f.Command); e != nil {
			d.errchan <- e
			return
		}
	default: // Other frames
		if e := f.writeFrame(c.wtr, c.protocol); e != nil {
			d.errchan <- e
			return
		}
		if e := c.wtr.WriteByte('\x00'); e != nil {
			d.errchan <- e
			return
		}
	}
	if e := c.wtr.Flush(); e != nil {
		d.errchan <- e
		return
	}
	//
	if c.hbd != nil {
		c.hbd.ls = time.Nanoseconds() // Latest good send
	}
	//
	d.errchan <- nil
	return
}

// Frame writer
func (f *Frame) writeFrame(w io.Writer, l string) (e os.Error) {
	// Write the frame Command
	if _, e = fmt.Fprintf(w, "%s\n", f.Command); e != nil {
		return e
	}
	// Write the frame Headers
	for i := 0; i < len(f.Headers); i += 2 {
		k := f.Headers[i]
		v := f.Headers[i+1]<commit_msg>Always add content-length to outbound frames if a) user does not suppress, and b) user does not supply it.<commit_after>//
// Copyright © 2011 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package stomp

import (
	"fmt"
	"io"
	"os"
	"strconv"
	"time"
)

// Network writer
func (c *Connection) writer() {
	q := false
	for {

		select {
		case d := <-c.output:
			c.wireWrite(d)
		case q = <-c.wsd:
			break
		}

		if q {
			break
		}

	}

}

// Wiredata write
func (c *Connection) wireWrite(d wiredata) {
	f := d.frame
	switch f.Command {
	case "\n": // HeartBeat frame
		if _, e := fmt.Fprintf(c.wtr, "%s", f.Command); e != nil {
			d.errchan <- e
			return
		}
	default: // Other frames
		if e := f.writeFrame(c.wtr, c.protocol); e != nil {
			d.errchan <- e
			return
		}
		if e := c.wtr.WriteByte('\x00'); e != nil {
			d.errchan <- e
			return
		}
	}
	if e := c.wtr.Flush(); e != nil {
		d.errchan <- e
		return
	}
	//
	if c.hbd != nil {
		c.hbd.ls = time.Nanoseconds() // Latest good send
	}
	//
	d.errchan <- nil
	return
}

// Frame writer
func (f *Frame) writeFrame(w io.Writer, l string) (e os.Error) {
	// Write the frame Command
	if _, e = fmt.Fprintf(w, "%s\n", f.Command); e != nil {
		return e
	}
	// Content length - Always add it if client does not suppress it and
	// does not supply it.
	if _, ok := f.Headers.Contains("suppress-content-length"); !ok {
		if _, clok := f.Headers.Contains("content-length"); !clok {
			l := strconv.Itoa(len(f.Body))
			f.Headers = f.Headers.Add("content-length", l)
		}
	}
	// Write the frame Headers
	for i := 0; i < len(f.Headers); i += 2 {
		k := f.Headers[i]
		v := f.Headers[i+1]
{'fraction_non_alphanumeric': 0.15345137285091096, 'fraction_numerical': 0.006671798819604825, 'mean_word_length': 2.56959706959707, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '161178', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1403, 'n_words': 475}