mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Split reopen into close/open.
Only call close if there's already a writer, which avoids flushing packets before the first call.
This commit is contained in:
parent
99055e5cae
commit
e3c8645897
1 changed files with 22 additions and 15 deletions
|
@ -184,15 +184,10 @@ func (conn *diskConn) warn(message string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// called locked
|
// called locked
|
||||||
func (conn *diskConn) reopen(extension string) error {
|
func (conn *diskConn) open(extension string) error {
|
||||||
for _, t := range conn.tracks {
|
if conn.file != nil {
|
||||||
t.writeBuffered(true)
|
return errors.New("already open")
|
||||||
if t.writer != nil {
|
|
||||||
t.writer.Close()
|
|
||||||
t.writer = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
conn.file = nil
|
|
||||||
|
|
||||||
file, err := openDiskFile(conn.directory, conn.username, extension)
|
file, err := openDiskFile(conn.directory, conn.username, extension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -203,10 +198,8 @@ func (conn *diskConn) reopen(extension string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *diskConn) Close() error {
|
// called locked
|
||||||
conn.remote.DelLocal(conn)
|
func (conn *diskConn) close() []*diskTrack {
|
||||||
|
|
||||||
conn.mu.Lock()
|
|
||||||
tracks := make([]*diskTrack, 0, len(conn.tracks))
|
tracks := make([]*diskTrack, 0, len(conn.tracks))
|
||||||
for _, t := range conn.tracks {
|
for _, t := range conn.tracks {
|
||||||
t.writeBuffered(true)
|
t.writeBuffered(true)
|
||||||
|
@ -216,6 +209,15 @@ func (conn *diskConn) Close() error {
|
||||||
}
|
}
|
||||||
tracks = append(tracks, t)
|
tracks = append(tracks, t)
|
||||||
}
|
}
|
||||||
|
conn.file = nil
|
||||||
|
return tracks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (conn *diskConn) Close() error {
|
||||||
|
conn.remote.DelLocal(conn)
|
||||||
|
|
||||||
|
conn.mu.Lock()
|
||||||
|
tracks := conn.close()
|
||||||
conn.mu.Unlock()
|
conn.mu.Unlock()
|
||||||
|
|
||||||
for _, t := range tracks {
|
for _, t := range tracks {
|
||||||
|
@ -557,9 +559,14 @@ func (t *diskTrack) writeBuffered(force bool) error {
|
||||||
|
|
||||||
// called locked
|
// called locked
|
||||||
func (conn *diskConn) initWriter(width, height uint32) error {
|
func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
if conn.file != nil && width == conn.width && height == conn.height {
|
if conn.file != nil {
|
||||||
return nil
|
if width == conn.width && height == conn.height {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isWebm := true
|
isWebm := true
|
||||||
var desc []mkvcore.TrackDescription
|
var desc []mkvcore.TrackDescription
|
||||||
for i, t := range conn.tracks {
|
for i, t := range conn.tracks {
|
||||||
|
@ -630,7 +637,7 @@ func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
header = &h
|
header = &h
|
||||||
}
|
}
|
||||||
|
|
||||||
err := conn.reopen(extension)
|
err := conn.open(extension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue