Giter Club home page Giter Club logo

Comments (10)

xamino avatar xamino commented on June 22, 2024

So I gave it a try and came up with the following. However I do not seem to be able to get it to compile / work or even test it. I'll post it here in the hope that it isn't all too wrong.

/*
FileSend sends a file transmission request.
*/
func (t *Tox) FileSend(friendnumber uint32, fileKind ToxFileKind, filelength uint64, fileID uint8, filename string) (uint32, error) {
    if t.tox == nil {
        return 0, ErrBadTox
    }

    var cFileKind = C.TOX_FILE_KIND_DATA
    switch ToxFileKind(fileKind) {
    case TOX_FILE_KIND_AVATAR:
        cFileKind = C.TOX_FILE_KIND_AVATAR
    case TOX_FILE_KIND_DATA:
        cFileKind = C.TOX_FILE_KIND_DATA
    }

    cFilename := (*C.uint8_t)(&[]byte(filename)[0])

    var toxErrfileControl C.TOX_ERR_FILE_CONTROL
    n := C.tox_file_send(t.tox, (C.uint32_t)(friendnumber), cFileKind, (C.uint64_t)(length), (C.uint8_t)(fileID), cFilename, (C.size_t)(len(filename)), &toxErrfileControl)
    // check if all ok
    filenumber := uint32(n)
    if filenumber == math.MaxUint32 || ToxErrFileControl(toxErrfileControl) != TOX_ERR_FILE_CONTROL_OK {
        return 0, ErrFuncFail
    }
    return filenumber, nil
}

/*
FileSendChunk sends a file chunk to a friend.
*/
func (t *Tox) FileSendChunk(friendnumber uint32, filenumber uint32, position uint64, data []byte, length uint64) error {
    if t.tox == nil {
        return ErrBadTox
    }

    cData := (*C.uint8_t)(&data[0])

    var toxErrfileControl C.TOX_ERR_FILE_CONTROL
    success := C.tox_file_send_chunk(t.tox, (C.uint32_t)(friendnumber), (C.uint32_t)(filenumber), (C.uint64_t)(position), cData, (C.uint64_t)(length), &toxErrfileControl)
    if !bool(success) || ToxErrFileControl(toxErrfileControl) != TOX_ERR_FILE_CONTROL_OK {
        return ErrFuncFail
    }
    return nil
}

from go-tox.

codedust avatar codedust commented on June 22, 2024

Thanks! I don't have much time atm but I'll give it a try this evening.

from go-tox.

xamino avatar xamino commented on June 22, 2024

Fantastic, thank you very much!

from go-tox.

codedust avatar codedust commented on June 22, 2024

Done. ;)
tox_file_seek and tox_file_get_file_id are still missing. Let me know when you need them.

from go-tox.

xamino avatar xamino commented on June 22, 2024

Thank you very much, works like a charm. Except: if I check for errors on calling t.FileSendChunk(friendNumber, fileNumber, position, data) in onFileChunkRequest, I always get an error back, specifically the "Function Failed" error (both in my code and in the example.go file if you catch the return of the function). The file is correctly received and valid, I have checked that. Not critical but a small bug. 😉

Otherwise I think I have all the functionality I'll require from here on out, so you should be safe from me for now. Cheers!

from go-tox.

codedust avatar codedust commented on June 22, 2024

Thanks for your bug report! The error is thrown because we try to call FileSendChunk with len(data) == 0 when the file transfer is already completed. This is because onFileChunkRequest is called with a length of 0 when the file transfer is finished.

If the length parameter is 0, the file transfer is finished, and the client's resources associated with the file number should be released. [...]
For files with known size, Core will know that the transfer is complete after the last byte has been received, so it is not necessary (though not harmful) to send a zero-length chunk to terminate.
-- tox.h

I updated example.go to comply with this specification.

from go-tox.

xamino avatar xamino commented on June 22, 2024

Ah, so a bug on my side, specifically the user side. 😛 I've modified my code accordingly, now it works perfectly.

Thanks again!

from go-tox.

codedust avatar codedust commented on June 22, 2024

Hi! I found the time to add the missing C bindings. When updating, make sure to remove the unnecessary arguments from gotox.FileControl() (see examples/example.go#L165).

from go-tox.

xamino avatar xamino commented on June 22, 2024

Thanks for the warning, I'll update my code now to stay up to date.

EDIT: Update worked perfectly, everything still runs on my side.

from go-tox.

codedust avatar codedust commented on June 22, 2024

Nice to hear that :)

from go-tox.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.