<commit_before>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build nacl

package xwebsocket

import (
	"net"
	"net/url"
	"runtime/ppapi"
	"sync"
	"time"

	"v.io/v23/context"
	"v.io/v23/flow"
)

// Ppapi instance which must be set before the Dial is called.
var PpapiInstance ppapi.Instance

func WebsocketConn(address string, ws *ppapi.WebsocketConn) flow.Conn {
	return &wrappedConn{
		address: address,
		ws:      ws,
	}
}

type wrappedConn struct {
	address   string
	ws        *ppapi.WebsocketConn
	readLock  sync.Mutex
	writeLock sync.Mutex
}

func Dial(ctx *context.T, protocol, address string, timeout time.Duration) (flow.Conn, error) {
	inst := PpapiInstance
	u, err := url.Parse("ws://" + address)
	if err != nil {
		return nil, err
	}

	ws, err := inst.DialWebsocket(u.String())
	if err != nil {
		return nil, err
	}
	return WebsocketConn(address, ws), nil
}

func Resolve(ctx *context.T, protocol, address string) (string, string, error) {
	return "ws", address, nil
}

func (c *wrappedConn) ReadMsg() ([]byte, error) {
	defer c.readLock.Unlock()
	c.readLock.Lock()
	return c.ws.ReceiveMessage()
}
<commit_msg>xwebsocket: Remove unused code.<commit_after>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build nacl

package xwebsocket

import (
	"net"
	"runtime/ppapi"
	"sync"

	"v.io/v23/flow"
)

// Ppapi instance which must be set before the Dial is called.
var PpapiInstance ppapi.Instance

func WebsocketConn(address string, ws *ppapi.WebsocketConn) flow.Conn {
	return &wrappedConn{
		address: address,
		ws:      ws,
	}
}

type wrappedConn struct {
	address   string
	ws        *ppapi.WebsocketConn
	readLock  sync.Mutex
	writeLock sync.Mutex
}

func (c *wrappedConn) ReadMsg() ([]byte, error) {
	defer c.readLock.Unlock()
	c.readLock.Lock()
	return c.ws.ReceiveMessage()
}

{'fraction_non_alphanumeric': 0.11629048086359176, 'fraction_numerical': 0.0068694798822374874, 'mean_word_length': 3.6340909090909093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4143146', 'n_tokens_mistral': 747, 'n_tokens_neox': 723, 'n_words': 224}