(ctx context.Context)
| 18 | } |
| 19 | |
| 20 | func (m *mysqlProxy) Run(ctx context.Context) { |
| 21 | m.ctx = ctx |
| 22 | m.closed.Store(true) |
| 23 | ln, err := net.Listen("tcp4", config.Get().Server.Addr) |
| 24 | if err != nil { |
| 25 | logrus.Errorf("IceFireDB-SQLite listen fail:%v", err) |
| 26 | return |
| 27 | } |
| 28 | utils.GoWithRecover(func() { |
| 29 | if <-ctx.Done(); true { |
| 30 | _ = ln.Close() |
| 31 | m.closed.Store(true) |
| 32 | } |
| 33 | }, nil) |
| 34 | |
| 35 | m.closed.Store(false) |
| 36 | |
| 37 | logrus.Infof("IceFireDB-SQLite listening:%s\n", config.Get().Server.Addr) |
| 38 | |
| 39 | // init sqlitedb |
| 40 | db := sqlite.InitSQLite(ctx, config.Get().SQLite.Filename) |
| 41 | m.db = db |
| 42 | for { |
| 43 | conn, err := ln.Accept() |
| 44 | if err != nil { |
| 45 | if errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) { |
| 46 | return |
| 47 | } |
| 48 | panic(err) |
| 49 | } |
| 50 | go m.onConn(conn) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func newMysqlProxy() *mysqlProxy { |
| 55 | p := &mysqlProxy{} |
no test coverage detected