• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang buffers.Put函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/calmh/syncthing/buffers.Put函数的典型用法代码示例。如果您正苦于以下问题:Golang Put函数的具体用法?Golang Put怎么用?Golang Put使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Put函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: copyRemoteBlocks

func (m *fileMonitor) copyRemoteBlocks(cc <-chan content, outFile *os.File, writeWg *sync.WaitGroup) {
	defer writeWg.Done()

	for content := range cc {
		_, err := outFile.WriteAt(content.data, content.offset)
		buffers.Put(content.data)
		if err != nil {
			m.writeError = err
			return
		}
	}
}
开发者ID:ngpestelos,项目名称:syncthing,代码行数:12,代码来源:filemonitor.go


示例2: externalLookup

func (d *Discoverer) externalLookup(node string) (string, bool) {
	extIP, err := net.ResolveUDPAddr("udp", d.extServer+":22025")
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return "", false
	}

	conn, err := net.DialUDP("udp", nil, extIP)
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return "", false
	}
	defer conn.Close()

	err = conn.SetDeadline(time.Now().Add(5 * time.Second))
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return "", false
	}

	_, err = conn.Write(EncodePacket(Packet{QueryMagic, 0, node, nil}))
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return "", false
	}

	var buf = buffers.Get(256)
	defer buffers.Put(buf)

	n, err := conn.Read(buf)
	if err != nil {
		if err, ok := err.(net.Error); ok && err.Timeout() {
			// Expected if the server doesn't know about requested node ID
			return "", false
		}
		log.Printf("discover/external/read: %v; no external lookup", err)
		return "", false
	}

	pkt, err := DecodePacket(buf[:n])
	if err != nil {
		log.Printf("discover/external/read: %v; no external lookup", err)
		return "", false
	}

	if pkt.Magic != AnnouncementMagic {
		log.Printf("discover/external/read: bad magic; no external lookup", err)
		return "", false
	}

	return fmt.Sprintf("%s:%d", ipStr(pkt.IP), pkt.Port), true
}
开发者ID:JoeX2,项目名称:syncthing,代码行数:52,代码来源:discover.go


示例3: applyContent

func applyContent(cc <-chan content, dst io.WriterAt) error {
	var err error

	for c := range cc {
		_, err = dst.WriteAt(c.data, c.offset)
		buffers.Put(c.data)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:philips,项目名称:syncthing,代码行数:13,代码来源:model_puller.go


示例4: processRequest

func (c *rawConnection) processRequest(msgID int, req RequestMessage) {
	data, _ := c.receiver.Request(c.id, req.Repository, req.Name, int64(req.Offset), int(req.Size))

	c.wmut.Lock()
	header{0, msgID, messageTypeResponse}.encodeXDR(c.xw)
	c.xw.WriteBytes(data)
	err := c.flush()
	c.wmut.Unlock()

	buffers.Put(data)

	if err != nil {
		c.close <- err
	}
}
开发者ID:nbrownus,项目名称:syncthing,代码行数:15,代码来源:protocol.go


示例5: processRequest

func (c *Connection) processRequest(msgID int, req request) {
	data, _ := c.receiver.Request(c.ID, req.name, req.offset, req.size, req.hash)

	c.Lock()
	c.mwriter.writeUint32(encodeHeader(header{0, msgID, messageTypeResponse}))
	c.mwriter.writeResponse(data)
	err := c.flush()
	c.Unlock()

	buffers.Put(data)
	if err != nil {
		c.Close(err)
	} else if c.mwriter.err != nil {
		c.Close(c.mwriter.err)
	}
}
开发者ID:philips,项目名称:syncthing,代码行数:16,代码来源:protocol.go


示例6: handleCopyBlock

func (p *puller) handleCopyBlock(b bqBlock) {
	// We have blocks to copy from the existing file
	f := b.file
	of := p.openFiles[f.Name]

	if debug {
		l.Debugf("pull: copying %d blocks for %q / %q", len(b.copy), p.repo, f.Name)
	}

	var exfd *os.File
	exfd, of.err = os.Open(of.filepath)
	if of.err != nil {
		if debug {
			l.Debugf("pull: error: %q / %q: %v", p.repo, f.Name, of.err)
		}
		of.file.Close()
		of.file = nil

		p.openFiles[f.Name] = of
		return
	}
	defer exfd.Close()

	for _, b := range b.copy {
		bs := buffers.Get(int(b.Size))
		_, of.err = exfd.ReadAt(bs, b.Offset)
		if of.err == nil {
			_, of.err = of.file.WriteAt(bs, b.Offset)
		}
		buffers.Put(bs)
		if of.err != nil {
			if debug {
				l.Debugf("pull: error: %q / %q: %v", p.repo, f.Name, of.err)
			}
			exfd.Close()
			of.file.Close()
			of.file = nil

			p.openFiles[f.Name] = of
			return
		}
	}
}
开发者ID:humanrelationshins,项目名称:syncthing,代码行数:43,代码来源:puller.go


示例7: copyLocalBlocks

func (m *fileMonitor) copyLocalBlocks(inFile, outFile *os.File, writeWg *sync.WaitGroup) {
	defer inFile.Close()
	defer writeWg.Done()

	var buf = buffers.Get(BlockSize)
	defer buffers.Put(buf)

	for _, lb := range m.localBlocks {
		buf = buf[:lb.Size]
		_, err := inFile.ReadAt(buf, lb.Offset)
		if err != nil {
			m.copyError = err
			return
		}
		_, err = outFile.WriteAt(buf, lb.Offset)
		if err != nil {
			m.copyError = err
			return
		}
	}
}
开发者ID:ngpestelos,项目名称:syncthing,代码行数:21,代码来源:filemonitor.go


示例8: handleRequestResult

func (p *puller) handleRequestResult(res requestResult) {
	p.oustandingPerNode.decrease(res.node)
	f := res.file

	of, ok := p.openFiles[f.Name]
	if !ok || of.err != nil {
		// no entry in openFiles means there was an error and we've cancelled the operation
		return
	}

	_, of.err = of.file.WriteAt(res.data, res.offset)
	buffers.Put(res.data)

	of.outstanding--
	p.openFiles[f.Name] = of

	if debug {
		l.Debugf("pull: wrote %q / %q offset %d outstanding %d done %v", p.repo, f.Name, res.offset, of.outstanding, of.done)
	}

	if of.done && of.outstanding == 0 {
		p.closeFile(f)
	}
}
开发者ID:humanrelationshins,项目名称:syncthing,代码行数:24,代码来源:puller.go


示例9: readString

func (r *marshalReader) readString() string {
	bs := r.readBytes()
	defer buffers.Put(bs)
	return string(bs)
}
开发者ID:JoeX2,项目名称:syncthing,代码行数:5,代码来源:marshal.go


示例10: externalLookup

func (d *Discoverer) externalLookup(node string) []string {
	extIP, err := net.ResolveUDPAddr("udp", d.extServer)
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return nil
	}

	conn, err := net.DialUDP("udp", nil, extIP)
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return nil
	}
	defer conn.Close()

	err = conn.SetDeadline(time.Now().Add(5 * time.Second))
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return nil
	}

	buf := QueryV2{QueryMagicV2, node}.MarshalXDR()
	_, err = conn.Write(buf)
	if err != nil {
		log.Printf("discover/external: %v; no external lookup", err)
		return nil
	}
	buffers.Put(buf)

	buf = buffers.Get(2048)
	defer buffers.Put(buf)

	n, err := conn.Read(buf)
	if err != nil {
		if err, ok := err.(net.Error); ok && err.Timeout() {
			// Expected if the server doesn't know about requested node ID
			return nil
		}
		log.Printf("discover/external/read: %v; no external lookup", err)
		return nil
	}

	if debug {
		dlog.Printf("read external:\n%s", hex.Dump(buf[:n]))
	}

	var pkt AnnounceV2
	err = pkt.UnmarshalXDR(buf[:n])
	if err != nil && err != io.EOF {
		log.Println("discover/external/decode:", err)
		return nil
	}

	if debug {
		dlog.Printf("parsed external: %#v", pkt)
	}

	var addrs []string
	for _, a := range pkt.This.Addresses {
		nodeAddr := fmt.Sprintf("%s:%d", net.IP(a.IP), a.Port)
		addrs = append(addrs, nodeAddr)
	}
	return addrs
}
开发者ID:psyvisions,项目名称:syncthing,代码行数:63,代码来源:discover.go



注:本文中的github.com/calmh/syncthing/buffers.Put函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang discover.AnnounceV2类代码示例发布时间:2022-05-24
下一篇:
Golang buffers.Get函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap