mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-03 19:48:04 +00:00 
			
		
		
		
	Merge pull request #52 from Krayons/master
Added timeout to deal with connecting to slow and unreliable IRCservers
This commit is contained in:
		
						commit
						57eecccd1b
					
				
					 1 changed files with 7 additions and 2 deletions
				
			
		| 
						 | 
					@ -23,8 +23,8 @@ type Conn struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Handlers
 | 
						// Handlers
 | 
				
			||||||
	intHandlers *hSet
 | 
						intHandlers *hSet
 | 
				
			||||||
	fgHandlers *hSet
 | 
						fgHandlers  *hSet
 | 
				
			||||||
	bgHandlers *hSet
 | 
						bgHandlers  *hSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// State tracker for nicks and channels
 | 
						// State tracker for nicks and channels
 | 
				
			||||||
	st         state.Tracker
 | 
						st         state.Tracker
 | 
				
			||||||
| 
						 | 
					@ -83,6 +83,9 @@ type Config struct {
 | 
				
			||||||
	// Split PRIVMSGs, NOTICEs and CTCPs longer than
 | 
						// Split PRIVMSGs, NOTICEs and CTCPs longer than
 | 
				
			||||||
	// SplitLen characters over multiple lines.
 | 
						// SplitLen characters over multiple lines.
 | 
				
			||||||
	SplitLen int
 | 
						SplitLen int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Timeout, The amount of time in seconds until a timeout is triggered.
 | 
				
			||||||
 | 
						Timeout time.Duration
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewConfig(nick string, args ...string) *Config {
 | 
					func NewConfig(nick string, args ...string) *Config {
 | 
				
			||||||
| 
						 | 
					@ -92,6 +95,7 @@ func NewConfig(nick string, args ...string) *Config {
 | 
				
			||||||
		NewNick:  func(s string) string { return s + "_" },
 | 
							NewNick:  func(s string) string { return s + "_" },
 | 
				
			||||||
		Recover:  (*Conn).LogPanic, // in dispatch.go
 | 
							Recover:  (*Conn).LogPanic, // in dispatch.go
 | 
				
			||||||
		SplitLen: 450,
 | 
							SplitLen: 450,
 | 
				
			||||||
 | 
							Timeout:  60 * time.Second,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cfg.Me.Ident = "goirc"
 | 
						cfg.Me.Ident = "goirc"
 | 
				
			||||||
	if len(args) > 0 && args[0] != "" {
 | 
						if len(args) > 0 && args[0] != "" {
 | 
				
			||||||
| 
						 | 
					@ -124,6 +128,7 @@ func Client(cfg *Config) *Conn {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dialer := new(net.Dialer)
 | 
						dialer := new(net.Dialer)
 | 
				
			||||||
 | 
						dialer.Timeout = cfg.Timeout
 | 
				
			||||||
	if cfg.LocalAddr != "" {
 | 
						if cfg.LocalAddr != "" {
 | 
				
			||||||
		if !hasPort(cfg.LocalAddr) {
 | 
							if !hasPort(cfg.LocalAddr) {
 | 
				
			||||||
			cfg.LocalAddr += ":0"
 | 
								cfg.LocalAddr += ":0"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue